n, k = gets.split.map &:to_i if k == 0 puts 1 else if n + 1 <= k puts 'INF' else bits = (0..30).select { |i| 2**i <= k && n[i] == 0 }.map { 2**_1 } puts [0, 1, 2].repeated_permutation(bits.size).count { |i| x = i.each_with_index.sum { _1 == 1 ? bits[_2] : 0 } y = i.each_with_index.sum { _1 == 2 ? bits[_2] : 0 } (0..k) === y - x } end end