
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    /// x -> (ax + b) % p
    static final int b = 1;
    static final int a = 618023;
    static final int p = 999983;
    
    static final void work(final long[] cur, final long is_on[], final int steps, final int d)
    {                
        final int not_skipped = steps - (steps % 8);
                
        for (int i = 0; i < not_skipped; i += 8)
        {
            cur[d + i + 0] ^= is_on[i + 0];
            cur[d + i + 1] ^= is_on[i + 1];
            cur[d + i + 2] ^= is_on[i + 2];
            cur[d + i + 3] ^= is_on[i + 3];
            cur[d + i + 4] ^= is_on[i + 4];
            cur[d + i + 5] ^= is_on[i + 5];
            cur[d + i + 6] ^= is_on[i + 6];
            cur[d + i + 7] ^= is_on[i + 7];
        }
                 
        for (int i = not_skipped; i < steps; i++)
            cur[d + i] ^= is_on[i];
    }

    static final int solve(int n, int s) {
        int cnt = 0;
        
        final long[] pref = new long[65];
        final long[] suff = new long[65];
        
        for (int i = 1; i <= 64; i++)
            pref[i] = (pref[i - 1] | (1L << (i - 1)));
        for (int i = 1; i <= 64; i++)
            suff[i] = (suff[i - 1] | (1L << (64 - i)));
        
        final int len = (p + 64) / 64;
        final long[][] pref_reprs = new long[64][len];
        final long[] is_on = new long[len];
        
        
        
        for (int iter = 0; iter < n; iter++)
        {
            s = (int)((a * 1L * s + b) % p);
            
            final int full = (s >> 6);
            final int part = (s & 63);
            
            
            long cur_layer = pref_reprs[0][full];
            for (int i = 1; i < 64; i++)
                cur_layer ^= ((pref_reprs[i][full] & pref[64 - i]) << i);
            
            if (full >= 1)
            {
                for (int i = 1; i < 64; i++)
                    cur_layer ^= ((pref_reprs[64 - i][full - 1] & suff[64 - i]) >>> i);
            }
            
            
            
            if ((cur_layer & (1L << part)) == 0L)
            {
                cnt++;
                is_on[full] |= (1L << part);
                
                work(pref_reprs[part], is_on, len - full, full);
            }
        }
        
        return cnt;
    }
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int s = scanner.nextInt();
        System.out.println(solve(n, s));
        scanner.close();
    }
}
