import java.io.*
import java.math.BigInteger
import java.util.StringTokenizer

const val M = 999_983

fun next(s: Int): Int {
  return ((s.toLong() * 618_023L + 1L) % M.toLong()).toInt()
}

fun main() {
  val (n, s0) = run {
    val inf = BufferedReader(InputStreamReader(System.`in`)); 
    val st = StringTokenizer(inf.readLine());
    val n = Integer.parseInt(st.nextToken())
    val s = Integer.parseInt(st.nextToken())
    n to s
  }
  //2^(M-1) corresponds to s = 0
  var bs = BigInteger.ZERO
  var x = BigInteger.ZERO
  var s = s0
  var ans = 0

  repeat (n) {
    s = next(s)
    val i = M - 1 - s
    if (!x.testBit(i)) {
      bs = bs.setBit(i)
      x = x.xor(bs.shiftRight(s))
      ans += 1
    }
  }
  println(ans)
}