a, b = gets.chomp.split(" ") def pow(n) n.times.inject(1){|a,b|a *= 10} end def calc(a) l = a.length if l == 1 return a[0] > 1 ? 1 : 0 end ret = 1 (0..l-2).each do |i| ret += a[0...i].join.to_i * pow(l-i-2) case a[i..i+1].join.to_i <=> 12 when -1 # when 0 ret += [a[i+2...l].join.to_i+1, 1].max when 1 ret += pow(l-i-2) else end if i > 0 ret += pow(l-i-2); else case a[0] <=> 2 when -1 # when 0 ret += a[1..l-2].join.to_i ret += 1 if a[l-1] >= 2 when 1 ret += pow(l-2) else end end end ret end ans = calc(b.chars.map &:to_i) - calc((a.to_i-1).to_s.chars.map &:to_i) ans -= 1 if a[0] == 2 && a[-1] == 1 p ans