class UnionFind def initialize(n) @size = Array.new(n, 1) @rank = Array.new(n, 0) @parent = [] (0..n).each do |i| @parent[i] = i end end def find(x) if @parent[x] == x x else @parent[x] = find(@parent[x]) end end def unite(x, y) x = find(x) y = find(y) return if x == y if @rank[x] < @rank[y] @parent[x] = y @size[y] += @size[x] else @parent[y] = x @size[x] += @size[y] @rank[x] += 1 if @rank[x] == @rank[y] end end def same?(x, y) find(x) == find(y) end def size(x) @size[find(x)] end end L, R = gets.split.map(&:to_i) table = Array.new(2 * R + 1, 0) uf = UnionFind.new(R + 1) ans = 0 L.upto(R) do |x| next if table[x] != 0 table[x] = 1 (2 * x).step(R, x) do |i| uf.unite(x, i) table[i] = 2 end end L.upto(R) do |x| next if table[x] != 1 if uf.same?(x, x - 1) next else uf.unite(x, x - 1) ans += 1 end end puts ans - 1