Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus's number.

Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.

NoteIn the first test sample all numbers that do not exceed 10 are undoubtedly lucky.In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.

n=int(input())
a=[]
def foo(x,i,j):
    if x>n:
        return
    if x:
        a.append(x)
    if 10*x+i!=x:
        foo(10*x+i,i,j)
    foo(10*x+j,i,j)
for i in range(10):
    for j in range(i+1,10):
        foo(0,i,j)
print(len(set(a)))

num=int(input());cou=0;
def traverse(x):
    if(x>num):return
    global cou
    if(len(set([int(j) for j in str(x)]))<=2):
        cou+=1
        for i in range(0,10):traverse(10*x+i)
for i in range(1,10):traverse(i)
print(cou)

# https://codeforces.com/contest/244/problem/B

def gen(digit, x, length, S):
    S.append(x)

    if length == 10:
        return

    if len(digit) == 1:
        for i in range(0, 10):
            next_x = x * 10 + i

            if i == digit[0]:
                gen(digit, next_x, length+1, S)
            else:
                gen(digit+[i], next_x, length+1, S)

    else:
        next_x1 = x * 10 + digit[0]
        next_x2 = x * 10 + digit[1]
        gen(digit, next_x1, length+1, S)
        gen(digit, next_x2, length+1, S)

S = []
for i in range(1, 10):
    gen([i], i, 1, S)

S = sorted(S)
x = int(input())

l = -1
u = len(S)

while u-l>1:
    md = (u+l) // 2
    if x >= S[md]:
        l = md
    else:
        u = md
print(u)

#CF Round 150. Div II Prob. A - Dividing Orange
import sys

dp = [[[-1 for j in range(3)] for i in range (1 << 10)] for k in range(11)]

In = sys.stdin
n = In.readline().strip()

def go (idx, mask, equal):
    if dp[idx][mask][equal] != -1:
        return dp[idx][mask][equal]
    if bin(mask).count("1") > 2:
        return 0
    if idx == len(n):
        return 1
    res = 0
    if idx == 0 or equal == 2:
        res += go(idx + 1, mask, 2)
    elif equal == 1 and int(n[idx]) == 0:
        res += go(idx + 1, mask | 1, 1)
    else:
        res += go(idx + 1, mask | 1, 0)
    for i in range(1, 10):
        if equal == 1 and i > int(n[idx]):
            break
        elif equal == 1 and i == int(n[idx]):
            res += go(idx + 1, mask | (1 << i), 1)
        else:
            res += go(idx + 1, mask | (1 << i), 0)
    dp[idx][mask][equal] = res
    return res

print(go(0, 0, 1)  - 1)

n = int(input())
res = set()

def solve(p, l):
    if p > n or l > 10:
        return
    if p > 0:
        res.add(p)
    solve(p * 10 + a, l + 1)
    solve(p * 10 + b, l + 1)

for a in range(0, 10):
    for b in range(0, a):
        solve(0, 0)
print(len(res))

"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

temp = pow(10, 8)

def dfs(number):
    if 0 < number <= n:
        answer[0] += 1
    if number >= temp:
        return
    for i in range(10):
        if number * 10 + i > 0:
            if len(set(str(number * 10 + i))) <= 2:
                dfs(number * 10 + i)

n = int(data())
answer = [0]
dfs(0)
if n == pow(10, 9):
    outln(answer[0] + 1)
    exit()
outln(answer[0])

def dfs(num):
  if 0 < num <= n:
    s.add(num)
    num*=10
    dfs(num+x)
    dfs(num+y)

n = int(input())
s = set()
for x in range(10):
  for y in range(10):
    dfs(x)

print(len(s))

#Copied

n = str(int(input()) + 1)
a = int(n[0])
l = len(n)
d = 1 << (l - 1)

def f(a, i):
    global n, l
    if i == l: return 0
    b = int(n[i])
    i += 1
    d = 1 << (l - i)
    if a > b: return b * d + g(b, a, i)
    if a == b: return b * d + f(a, i)
    return (b - 1) * d + g(a, b, i) + 9 * d - 8

def g(a, b, i):
    global n, l
    if i == l: return 0
    c = int(n[i])
    i += 1
    d = 1 << (l - i)
    if c < a: return 0
    if c == a: return g(a, b, i)
    if c < b: return d
    if c == b: return d + g(a, b, i)
    return 2 * d

print(a * (9 * d - 8) + 72 * (d - l) + f(a, 1) - 1)

def cnt(s, p):

    ans = 0

    if p > s: ans = 0

    elif len(p) == len(s):

        ans = 1 if len(set(p.lstrip('0'))) <= 2 else 0

    elif len(set(p.lstrip('0'))) > 2: ans = 0

    elif s[:len(p)] > p:

        if len(set(p.lstrip('0'))) == 2:

            ans = 2**(len(s)-len(p))

        elif len(set(p.lstrip('0'))) == 1:

            ans = 1 + 9 * (2**(len(s)-len(p)) - 1)

        else:

            # ab for all a, b != 0

            ans = 10 + 45 * (2**(len(s)-len(p)) - 2)

            ans += 36 * sum([2**l-2 for l in range(2,len(s)-len(p))])

    else: ans = sum(cnt(s, p+c) for c in '0123456789')

    return ans

print(cnt(input().strip(), '')-1)

# Made By Mostafa_Khaled

n=int(input())
curr=list([i for i in range(1,100)])
curr=set(curr)
def isvalid(x):
    if x<1 or x>10**9:
        return 0
    if len(set(str(x)))<=2:
        return 1
cnt=0
while cnt<=10**5 :
    curr1=set()
    for i in curr:
        for j in range(10):
            if isvalid(i*10+j):
                curr1.add(i*10+j)
               # print('hi')
                cnt+=1
    #print(curr1)
    curr|=curr1
curr=sorted(list(curr))
#print(curr)
ans=0
for i in curr:
    if i>=1 and i<=n:
        ans+=1
    elif i>n:
        break
print(ans)

n=int(input())
curr=list([i for i in range(1,100)])
curr=set(curr)
def isvalid(x):
    if x<1 or x>10**9:
        return 0
    if len(set(str(x)))<=2:
        return 1
cnt=0
while cnt<=9*(10**4 ):
    curr1=set()
    for i in curr:
        for j in range(10):
            if isvalid(i*10+j):
                curr1.add(i*10+j)
               # print('hi')
                cnt+=1
    #print(curr1)
    curr|=curr1
curr=sorted(list(curr))
#print(curr)
ans=0
for i in curr:
    if i>=1 and i<=n:
        ans+=1
    elif i>n:
        break
print(ans)

n=int(input())
curr=list([i for i in range(1,100)])
curr=set(curr)
def isvalid(x):
    if x<1 or x>10**9:
        return 0
    if len(set(str(x)))<=2:
        return 1
cnt=0
while cnt<=10**5:
    curr1=set()
    for i in curr:
        for j in range(10):
            if isvalid(i*10+j):
                curr1.add(i*10+j)

                cnt+=1
    #print(curr1)
    curr|=curr1
curr=sorted(list(curr))
#print(curr)
ans=0
for i in curr:
    if i>=1 and i<=n:
        ans+=1
    elif i>n:
        break
print(ans)

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

n = int(input())
if n < 100:
    print(n)
    sys.exit()
a = [[_,set(map(int,list(str(_))))] for _ in range(100)]
c = 99
for k in range(2,11):
    t = (10 ** (k-1))
    for aa in a:
        if aa[0] < t:
            aa[1] = aa[1] | set([0])
    at = a[:]
    for i in range(1,10):
        t = i * (10 ** k)
        for ai, ae in at:
            ac = ai + t
            if ac > n:
                print(c)
                sys.exit()
            if len(ae) < 2:
                ae = ae | set([i])
            if i in ae and len(ae) < 3:
                c += 1
                a.append([ac,ae])

#!/home/kameda/pyenv2/bin/python

power2list = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
'''
If the head of n (:(len(str(n))=i) is fixed as 'x',
number of candidates trailing digit is
9*(2^(i-1)-1)+1
9: len(range(0,10) except x)
(2^(i-1)-1): number of patterns like (xxy xyx xyy) if i=3
1: number of patterns like xxx if i=3

trailing_candidates = []
for i in range(1, 11):
    trailing_candidates.append(9*(2**(i-1)-1)+1)

'''
trailing_candidates = [1, 10, 28, 64, 136, 280, 568, 1144, 2296, 4600]
'''
For each head (1..9), trailing_candidates can be applied.
So, cumulative candidates lower than 10^i is calculated as below.

cumulative_candidates = [9]
for i in range(1, 10):
    cumulative_candidates.append(9*trailing_candidates[i]+cumulative_candidates[i-1])

'''
cumulative_candidates = [9, 99, 351, 927, 2151, 4671, 9783, 20079, 40743, 82143]

def main_y_fixed(n, y):
    #Count candidates which is n or less starting with n[0] (=x) given y (!=x)
    x = n[0]
    len_n = len(n)
    uln = 0
    if len_n == 1:
        return 1
    if int(y) > int(x):
        if int(n[1]) < int(x): # e.g. 42????? given 8 -> No candidates
            pass
        elif int(n[1]) == int(x): # e.g. 44????? given 8
            uln += main_y_fixed(n[1:], y)
        elif int(n[1]) < int(y): # e.g. 47????? given 8 -> 4488888 is the largest
            uln += power2list[len_n-2]
        elif int(n[1]) == int(y): # e.g. 48????? given 8
            uln += power2list[len_n-2]
            uln += main_y_fixed(n[1:], x)
        elif int(n[1]) > int(y): # e.g. 49????? given 8 -> 4888888 is the largest
            uln += power2list[len_n-1]
    elif int(y) == int(x):
        raise ValueError('2nd argument should be different from 1st degit of 1st argument')
    elif int(y) < int(x):
        if int(n[1]) < int(y): # e.g. 82????? given 4 -> No candidates
            pass
        elif int(n[1]) == int(y): # e.g. 84????? given 4
            uln += main_y_fixed(n[1:], x)
        elif int(n[1]) < int(y): # e.g. 87????? given 4 -> 8488888 is the largest
            uln += power2list[len_n-2]
        elif int(n[1]) == int(x): # e.g. 88????? given 4
            uln += power2list[len_n-2]
            uln += main_y_fixed(n[1:], y)
        elif int(n[1]) > int(y): # e.g. 89????? given 4 -> 8888888 is the largest
            uln += power2list[len_n-1]
    return uln

def main(n):
    #Count candidates which is n or less starting with n[0] (=x)
    x = n[0]
    len_n = len(n)
    uln = 0
    if len_n == 1:
        return 1
    if int(n[1]) > 0:
        for i in range(0, int(n[1])): #int(n[0]), ~int(n[1])-1 and all trailings
            if i != int(n[0]):
                uln += power2list[len_n-2]
            else:
                uln += trailing_candidates[len_n-2]
    if len_n == 2:
        return uln+1
    if int(n[0]) < int(n[1]):
        if int(n[2]) < int(n[0]): #e.g. 482????? -> 47777777 is the largest.
            pass
        elif int(n[2]) == int(n[0]): #e.g. 484?????
            uln += main_y_fixed(n[2:], n[1])
        elif int(n[2]) < int(n[1]): #e.g. 486????? -> 48488888 is the largest.
            uln += power2list[len_n-3]
        elif int(n[2]) == int(n[1]): #e.g. 488?????
            uln += power2list[len_n-3]
            uln += main_y_fixed(n[2:], n[0])
        elif int(n[2]) > int(n[1]): #e.g. 489?????
            uln += power2list[len_n-2]
    elif int(n[0]) == int(n[1]):
        uln += main(n[1:])
    elif int(n[0]) > int(n[1]):
        if int(n[2]) < int(n[1]): #e.g. 842????? -> 83333333 is the largest.
            pass
        elif int(n[2]) == int(n[1]): #e.g. 844?????
            uln += main_y_fixed(n[2:], n[0])
        elif int(n[2]) < int(n[0]): #e.g. 846????? -> 84488888 is the largest.
            uln += power2list[len_n-3]
        elif int(n[2]) == int(n[0]): #e.g. 848?????
            uln += power2list[len_n-3]
            uln += main_y_fixed(n[2:], n[1])
        elif int(n[2]) > int(n[0]): #e.g. 849?????
            uln += power2list[len_n-2]
    return uln

if __name__ == "__main__":
    N = raw_input()
    Len_N = len(N)
    if Len_N <= 2:
        print(N)
        exit(0)
    Uln = cumulative_candidates[Len_N-2] # below 10^len_n
    Uln += (int(N[0])-1)*trailing_candidates[Len_N-1] # between 10^len_n and n[0]*10^len_n
    Uln += main(N)
    print(Uln)
    exit(0)

# ~*~ coding:utf-8 ~*~
from itertools import combinations
from itertools import product
from itertools import combinations_with_replacement

n = int(raw_input())
d = len(str(n))
f = [[''.join(g)
     for g in list(product(('{0}', '{1}'), repeat=i))
      if g.count(g[0]) != len(g)]
     for i in xrange(1, d + 1)]

digits = list(combinations(range(10), 2))

r = 0
for i in xrange(d):
    for t in digits:
        for s in f[i]:
            if t[0] == 0 and s.startswith('{0}'):
                continue
            else:
                k = int(s.format(*t))
                if k <= n:
                    r += 1
    for j in xrange(1, 10):
        k = int(str(j) * (i + 1))
        if k <= n:
            r += 1
print r

def p(k):
	if 0<k<=n:s.add(k);k*=10;p(k+x);p(k+y)
n=input();s=set()
for x in range(10):
	for y in range(10):p(x)
print len(s)

n=input()
s=set()
for x in range(10):
  for y in range(x):
    for i in range(1<<10):
      v=0
      for j in range(10):
        v=v*10+(x if (1<<j)&i else y)
      while v>0:
        if v<=n:s.add(v)
        v/=10
print len(s)

def dfs(n,v,x,y,s):
  if v<=n:
    s.add(v)
    if v*10+x!=v: dfs(n,v*10+x,x,y,s)
    if v*10+y!=v: dfs(n,v*10+y,x,y,s)
n=input()
s=set()
for x in range(10):
  for y in range(x):
    dfs(n,0,x,y,s)
print len(s)-1

if __name__ == '__main__':
	vn = [int(_) for _ in list(raw_input())]
	n = len(vn)
	s = 81 * (1 << (n - 1)) - 72 * n - 9
	for i in range(n):
		for r in range(vn[i]) if i > 0 else range(1, vn[0]):
			k = len(set(vn[:i] + [r]))
			if k == 1:
				s += 9 * (1 << (n - 1 - i)) - 8
			elif k == 2:
				s += 1 << (n - 1 - i)
	if len(set(vn)) <= 2:
		s += 1
	print s

n = input()
import itertools
l = len(str(n))
C = list(itertools.combinations(['0','1','2','3','4','5','6','7','8','9'], 2))
LEVEL_VS_NUMBERS = {}
def choose_this_or_zero(x):
    x = int("".join(x))
    return x if x <= n else 0
res = set()
for i in range(1,l+1):
    for e in C:
        res.update(set(map(choose_this_or_zero, itertools.product(e, repeat=i))))
print len(res) - 1

n = input()
import itertools
l = len(str(n))
C = list(itertools.combinations(['0','1','2','3','4','5','6','7','8','9'], 2))
LEVEL_VS_NUMBERS = {}
for i in range(1,l+1):
    LEVEL_VS_NUMBERS[i] = set()
    for e in C:
        LEVEL_VS_NUMBERS[i].update(set(map(lambda t: int("".join(t)), itertools.product(e, repeat=i))))
LEVEL_VS_NUMBERS[l] = set([num for num in LEVEL_VS_NUMBERS[l] if num <= n])
res = set()
map(lambda x: res.update(x), LEVEL_VS_NUMBERS.values())
print len(res) - 1

crap = raw_input().split()
t,h,n = (int(crap[0]), str(crap[0]), len(str(crap[0])))
strings = []

def dfs(a, n, i, j):
	global strings
	if len(a) == n:
		if a[0] == "0":
			return
		strings.append(a)
		return
	dfs(a+str(i),n,i,j)
	dfs(a+str(j),n,i,j)

def query(i, j, n):
	global strings
	a = ""
	dfs(a, n, i, j)

for l in xrange(1, n+1):
	for i in xrange(10):
		for j in xrange(i):
			query(i,j,l)

setstrings = set(strings)
counter = 0
for value in setstrings:
	if int(value) <= t:
		counter += 1

print counter

counter = dict()
def calculate(x, y, actual, limit):
    #print x, y, actual, limit, 10 * actual + x, 10 * actual + y
    if actual > limit:
        return 0
    counter[actual] = 1
    if x == y:
        return calculate(x, y, 10 * actual + x, limit)
    if actual == 0 and (x == 0 or y == 0):
        if x == 0:
            calculate(x, y, 10 * actual + y, limit)
        else:
            calculate(x, y, 10 * actual + x, limit)
    else:
        calculate(x, y, 10 * actual + x, limit)
        calculate(x, y, 10 * actual + y, limit)
    return 0

n = int(raw_input())
for x in xrange(10):
    for y in xrange(x, 10):
        if x + y != 0:
            calculate(x, y, 0, n)

#print counter
print len(counter) - 1

import sys
def RedirectIO():
    sys.stdin=open("test.in","r")
#    sys.stdout=open("output.txt","w")
#RedirectIO()
def check(x,y):
    a=b=-1
    if x==0:
        a=0
    while x:
        m=x%10
        x/=10
        if a==-1:
            a=m
        elif a!=m and b==-1:
            b=m
    if b==-1:
        return True
    if y==a or y==b:
        return True
    return False;
def main():
    temp=n=input()
    if n<=10:
        print n
        return
    bits=0
    while temp:
        temp/=10
        bits+=1
    num=[x for x in xrange(1,10)]
    newNum=[]
    ans=9
    for i in xrange(2,bits+1):
        for y in xrange(10):
            for x in num:
                if y<x*10+y<=n and check(x,y):
                    ans+=1
                    newNum.append(x*10+y)
        num=newNum
        newNum=[]
    print ans
main()

n = int(raw_input())
ans = {}

def dfs(k, a, b):
        if k <= n:
                ans[k] = 1
                if k != k * 10 + a:
                        dfs(k * 10 + a, a, b)
                if k != k * 10 + b:
                        dfs(k * 10 + b, a, b)

for i in range(10):
        for j in range(i + 1):
                dfs(0, i, j)

print len(ans) - 1

ans = 0
val = int(raw_input())
def fun(n):
    global val
    global ans
    if(n > 0 and n <= val):
        ans += 1
    if n >= 10**9:
        return
    for a in range(10):
        if(n*10 + a) > 0:
            if len(set((str(n*10 + a)))) <= 2:
                fun(n*10 + a)
fun(0)
print ans

n = input()

if n <= 10:
	print n
else:
	cnt = 9
	le = len(str(n))
	i = 2
	while i <= le-1:
		cnt += ((81*((1<<(i-1))-1) + 9))
		i += 1

	d = {}

	for i in xrange(1,10):
		d[(int(str(i)*le))] = 1

	for i in xrange(1,10):
		for j in xrange(10):
			if i != j:
				mask = 0
				while mask < (1<<le-1):
					tmp = ""
					for k in xrange(le-1):
						if (mask&(1<<k)) > 0:
							tmp = str(i) + tmp
						else:
							tmp = str(j) + tmp
					tmp = str(i) + tmp
					d[(int(tmp))] = 1
					mask += 1

	for key in d:
		if key <= n:
			cnt += 1
	print cnt

def dfs(num):
	if 0< num <=n:
		s.add(num)
		num *= 10
		dfs(num+x)
		dfs(num+y)
n=input()
s=set()
for x in xrange(10):
	for y in xrange(10):
		dfs(x)
print len(s)

n=input()

r=0
def dfs(a):
    r=0
    if a > 0 and a <= n: r+=1
    if a > n or a > 10**8: return r
    for d in range(10):
        if len(set(str(a*10+d))) < 3 and a*10+d:
            r+=dfs(a*10+d)
    return r

r+=dfs(0)
print r

n=input()

r=0
def dfs(a):
    #print a
    r=0
    if a > 0 and a <= n: r+=1
    if a > n or a > 10**8: return r
    for d in range(10):
        #print d,len(set(str(a*10+d))),a*10+d
        if len(set(str(a*10+d))) < 3 and a*10+d:
            r+=dfs(a*10+d)
    return r

r+=dfs(0)
print r

'''

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.

'''

import math
count = 0
n = 0
def distinct_digits(a):
	d= {}
	for i in a:
		d[i] = 1
	return len(d)

def fn(num):
	global count, n
	if (num > 0 and num <= n):
		count+=1
	if (num > 10**8):
		return
  	for a  in range(0, 10):
    		if num*10+a > 0 and distinct_digits(str( num*10+a )) <= 2:
			        fn( num*10+a )

if __name__ == '__main__':
	n=input()
	fn(0)
	print count

n = input()
r = set()

def f(v):
	if v <= n:
		r.add(v)
		v *= 10
		if v or x:
			f(v + x)
		if v or y:
			f(v + y)
	v *= 10

for x in range(10):
	for y in range(10):
		f(0)
print len(r) - 1

n = input()
print sum(0 < v <= n for v in set([int(s.replace('a', `x`).replace('b', `y`)) for x in range(10) for y in range(10) for s in [('0' * l + bin(m)[2 : ])[-l - 1 : ].replace('0', 'a').replace('1', 'b') for l in range(9) for m in range(2 << l)]] + [10 ** 9]))

def f(v):
	if 0 < v <= n:
		v *= 10
		r.add(v)
		f(v + x)
		f(v + y)

n = input()
r = set()
for x in range(10):
	for y in range(10):
		f(x)
print len(r)

n = input()
r = set()

def f(v):
	if 0 < v <= n:
		v *= 10
		r.add(v)
		f(v + x)
		f(v + y)

for x in range(10):
	for y in range(10):
		f(x)
print len(r)

####################################################
# -*- coding: utf-8 -*-
import sys

w = sys.stdout.write
read = sys.stdin.readline
reads = sys.stdin.read

def r(f=None):
    if f:
        return map(f, read().split())
    else:
        return read().split()

def rs(t,f=None):
    result = []
    result_append = result.append
    for i in xrange(t):
        if f:
            result_append(tuple(map(f, read().split())))
        else:
            result_append(list(read().split()))
    return result

####################################################
import math
sqrt = math.sqrt
from collections import deque

[n] = r(int)
s = set([])
def dfs(num, a, b):
    if num <= n:
        s.add(num)
        if num*10+a != num: dfs(10*num+a, a, b)
        if num*10+b != num: dfs(10*num+b, a, b)

for x, y in [(x, y) for x in range(10) for y in range(10)]:
    dfs(0, x, y)

w(str(len(s)-1))

#!/usr/bin/python

import os
import sys
import itertools
import collections

def solve(f):
    n = f.read_int()
    nlen = len(str(n))

    ans = set()

    for x, y in itertools.combinations(range(10), 2):
        for ni in xrange(1,nlen+1):
            for item in itertools.product([x, y], repeat=ni):
                if item[-1] == 0: continue
                cand = sum([j*10**i for i, j in enumerate(item)])
                if cand <= n: ans.add(cand)

    print len(ans)

class Reader(object):
    def __init__(self, filename=None):
        self.test_mode = filename is not None
        self.cases = 1
        self.buffer = []
        if self.test_mode:
            with open(filename) as f:
                blank_flg = False
                for line in f:
                    line = line.strip()
                    if line:
                        self.buffer.append(line)
                        blank_flg = False
                    else:
                        if not blank_flg: self.cases += 1
                        blank_flg = True

    def __readline(self):
        return self.buffer.pop(0) if self.test_mode else raw_input()

    def read_int(self):
        return int(self.__readline())
    def read_float(self):
        return float(self.__readline())
    def read_long(self):
        return long(self.__readline())
    def read_str(self):
        return self.__readline()

    def read_int_list(self):
        return [int(item) for item in self.__readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.__readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.__readline().split()]
    def read_str_list(self):
        return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv)>1 else None
    f = Reader(filename)
    if f.test_mode:
        for c in xrange(f.cases):
            print "Case #%d"%(c+1)
            solve(f)
    else:
        solve(f)

n = int(raw_input())

r = set()

def tt(a, x, y):
    if a <= n:
        r.add(a)
        if (a * 10 + x != a): tt(a * 10 + x, x, y)
        if (a * 10 + y != a): tt(a * 10 + y, x, y)

for x in xrange(1, 10):
    for y in xrange(0, x+1):
        tt(0, x, y)

print len(r)-1

def p(k):
	if 0<k<=n:s.add(k);k*=10;p(k+x);p(k+y)
n=input();s=set()
for x in range(10):
	for y in range(10):p(x)
print len(s)

import sys

n = int(raw_input()) + 1
ans = 0
tmp = []
def dfs(num, x, y, inx, iny):
  global ans
  if num < n and inx and iny :
    ans += 1
#    tmp.append(num)
  if num > n:
    return
  if x or num :
    if num*10 + x < n:
      dfs(num*10 + x, x, y, 1, iny)
  if y or num :
    if num*10 + y < n:
      dfs(num*10 + y, x, y,inx, 1)

for x in range(0,10):
  for y in range(x + 1, 10):
    if x:
      dfs(y, x, y, 0, 1)
    dfs(x, x, y, 1, 0)
print ans
#print len(tmp), sorted(tmp)

import sys
import math
import string
from collections import deque

# Function #
def read_int() :
    temp = raw_input().split();
    return map(int, temp);

def read_str() :
    temp = raw_input().split();
    return temp;

def write(output) :
    sys.stdout.write(output);

def writeln(output) :
    sys.stdout.write(str(output)+'\n');
# Class #

INF = 9123456789123456789
# Main Entry #

# Inner Function #

ans = set();

if __name__ == '__main__':

    def dfs(now, x, y) :
        if now <= tc :
            if now != 0 :
                ans.add(now);
            if now*10+x != 0 :
                dfs(now*10+x, x, y);
            if now*10+y != 0 :
                dfs(now*10+y, x, y);

    tc = read_int()[0];

    for ii in xrange(0, 10) :
        for jj in xrange(ii+1, 10) :
            dfs(0, ii, jj);

    print len(ans);

    pass
# End Here #

n = input()

from itertools import *

def GEN(x,y):
 Q,i = [ 0 ],0
 while i!= len(Q):
  t = Q[i]
  if t>n: break
  Q += [ Q[i]*10+x , Q[i]*10+y]
  i+=1
 return Q

print len(set(map(int,reduce(lambda x,y: x+y, [ [ k for k in GEN(i,j) if k<=n] for i,j in combinations(range(0,10),2)]))))-1

entrada = int(raw_input())
r = 0

def generador(n):
   global r
   global entrada
   for i in xrange(0,10):
      if n*10+i >0 and n*10+i <= entrada and valido(n*10+i):
         r+=1
         generador(n*10+i)

def valido(n):
   return len(set(str(n)))<=2

generador(0)
print r

#!/usr/bin/env python

from sys import stdin

n = int(stdin.readline())

def spam(m):
    if m <= n:
        s.add(m)
        if m or a: spam(m*10+a)
        if m or b: spam(m*10+b)

s = set()
for a in range(0, 10):
    for b in range(a+1, 10):
        spam(0)
s.remove(0)
print(len(s))

n=input()
st=set()
def dfs(x,l):
    if l>10 or x>n:return
    if x: st.add(x)
    dfs(10*x+a,l+1)
    dfs(10*x+b,l+1)

for a in xrange(10):
    for b in xrange(a+1,10):
        dfs(0,0)
print len(st)

n=input()

cnt=0
def dfs(i):
    global cnt,n
    if i>n: return
    if len(set(str(i)))<=2: cnt+=1
    else:return
    for x in xrange(10):
        if i or x: dfs(10*i+x)
dfs(0)
print cnt-1

n=input()
ans=set()

def dfs(p,l):
    if p>n or l>10:
        return
    if p>0:
        ans.add(p)
    dfs(p*10+a,l+1)
    dfs(p*10+b,l+1)

for a in range(0,10):
    for b in range(0,a):
        dfs(0,0)
print "%d" % len(ans)

n = input()
ans = set()
for i in range(10):
    for j in range(i + 1, 10):
        l = []
        if i and i <= n: l.append(i)
        if j and j <= n: l.append(j)
        L = len(l)
        t = 0
        while t < L:
          #  print "======"
            s = l[t]
            if s * 10 + i <= n :
                l.append(s * 10 + i)
                L += 1
            if s * 10 + j <= n :
                l.append(s * 10 + j)
                L += 1
            t += 1
        for k in l:
            ans.add(k)
print len(ans)

n = input()
def dfs(x):
    if(x <= n):
        ans.add(x)
        if x or i : dfs(x * 10 + i)
        if x or j : dfs(x * 10 + j)
ans = set()
for i in range(10) :
    for j in range(i + 1, 10) :
        dfs(0)
print (len(ans) - 1)

N=int(raw_input())
ans=0

def fun(n):
    global N,ans
    if n>0 and n<=N:
        ans+=1
    if n>=10**9:
        return
    for i in range(10):
        if 10*n+i>0:
            if len(set(str(10*n+i)))<=2:
                fun(10*n+i)
fun(0)
print ans

# -*- coding: utf-8 -*-
"""
Created on Sat Nov 17 12:35:15 2012

@author: bluebird
"""
class solve:
    def __init__(self,n):
        self.s = set()
        self.n = n
    def answer(self):
        for x in range(10):
            for y in range(10):
                self.dfs(x,y,0)
        return len(self.s) - 1
    def dfs(self,i,j,t):
        if t <= self.n:
            self.s.add(t)
            if t != t*10 + i: self.dfs(i,j,t*10+i)
            if t != t*10 + j: self.dfs(i,j,t*10+j)

def main():
    n = int(input())
    test = solve(n)
    print test.answer()

if __name__ == "__main__":
    main()

def main():
    def dfs(v, x, y):
        if v <= n:
            s.add(v)
            if v*10+x != v:
                dfs(v*10+x, x, y)
            if v*10+y != v:
                dfs(v*10+y, x, y)

    n = input()
    s = set()
    for x in xrange(10):
        for y in xrange(x):
            dfs(0, x, y)
    print len(s)-1

if __name__ == '__main__':
    main()

def countDigits(n):
    cnt = 0
    while n:
        n /= 10
        cnt += 1
    return cnt

def makeNum(d1, d2, l, i):
    num = 0
    for j in range(l):
        num *= 10
        if (1 << j) & i:
            num += d1
        else:
            num += d2
    return num

n = int(raw_input())

ret = set()
digits = countDigits(n)
for d1 in range(10):
    for d2 in range(d1 + 1, 10):
        for i in range(2 ** digits):
            for l in range(1, digits + 1):
                num = makeNum(d1, d2, l, i)
                if num <= n:
                    ret.add(num)

print len(ret) - 1

a = [[0,1,2,3,4,5,6,7,8,9]]

def f():
    for i in xrange(8):
        b = []
        for j in xrange(1,10):
            for k in xrange(len(a)):
                for t in a[k]:
                    n = str(j) + "0"*(i-k)+str(t)
                    if (len(set(n)) < 3):
                        b.append(int(n))
        a.append(b)

f()

b = [ x for i in xrange(len(a)) for x in a[i]]
b.append(10**9)
b.append(10**9+1)
n = int(raw_input())

for i in xrange(len(b)):
    if b[i] > n:
        print i-1
        break

def p(k):
    if 0 < k <= n:
        s.add(k)
        k *= 10
        p(k + x)
        p(k + y)

n = int(input())
s = set()
for x in range(10):
    for y in range(10):
        p(x)
print(len(s))

n=int(input())
array=set()
array.add(10**9)
for x in range(10):
    for y in range(10):
        for l in range(1, 10):
            for m in range(1, 2 ** l + 1):
                s = [str(x) if m & (1 << i) else str(y) for i in range(l)]
                u = int(''.join(s))
                if u <= n:
                    array.add(u)
array.remove(0)
# print (sorted(list(array)))
array=[u for u in array if u <= n]
print(len(array))

ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
q =[]
s=set()
n=ii()
for x in range(10):
	for y in range(10):
		q.append(x)
		while q:
			q2 = []
			for item in q:
				if item > 0 and item <= n:
					s.add(item)
					item*=10
					q2.append(item+x)
					q2.append(item+y)
			q=q2
print(len(s))

from copy import deepcopy

N = input()
A = [ ord( N[ i ] ) - ord( '0' ) for i in range( len( N ) ) ]

dp = [ 0, 0 ]
dp = [ deepcopy( dp ) for i in range( 10 + 1 ) ]
dp = [ deepcopy( dp ) for i in range( 10 + 1 ) ]
dp = [ deepcopy( dp ) for i in range( len( A ) + 1  ) ]
dp[ 0 ][ 10 ][ 10 ][ 0 ] = 1

for i in range( len( A ) ):
  for j in range( 10 + 1 ):
    for k in range( 10 + 1 ):
      for l in range( 2 ):
        lim = 9
        if not l:
          lim = A[ i ]
        for d in range( lim + 1 ):
          if d == 0 and j == 10 and k == 10:
            dp[ i + 1 ][ 10 ][ 10 ][ 1 ] += dp[ i ][ j ][ k ][ l ]
          else:
            if j == 10 or j == d:
              dp[ i + 1 ][ d ][ k ][ l or d < lim ] += dp[ i ][ j ][ k ][ l ]
            else:
              if k == 10:
                if d < j:
                  dp[ i + 1 ][ d ][ j ][ l or d < lim ] += dp[ i ][ j ][ k ][ l ]
                else:
                  dp[ i + 1 ][ j ][ d ][ l or d < lim ] += dp[ i ][ j ][ k ][ l ]
              else:
                if d != j and d != k: continue
                dp[ i + 1 ][ j ][ k ][ l or d < lim ] += dp[ i ][ j ][ k ][ l ]

ans = 0
for i in range( 10 ):
  for j in range( 10 + 1 ):
    for k in range( 2 ):
      ans += dp[ len( A ) ][ i ][ j ][ k ]

print( ans )

#d=sorted(d,key=lambda x:(len(d[x]),-x))  d=dictionary     d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
def dfs(x):
    if 0< x <=n :
        s.add(x)
        x*=10
        dfs(x+i)
        dfs(x+j)

n=int(input())
#arr = list(map(int, input().split()))
s=set()

for i in range(1,10):
    for j in range(10):
        dfs(i)
print(len(s))

def dfs(num):
  if 0 < num <= n:
    s.add(num)
    num*=10
    dfs(num+x)
    dfs(num+y)

n = int(input())
s = set()
for x in range(10):
  for y in range(10):
    dfs(x)

print(len(s))

def find(x):
    if 0<x<=n:
        p.add(x)
        x*=10
        find(x+i)
        find(x+j)
n=int(input())
p= set()
for i in range(10):
    for j in range(10):
        find(i)
print(len(p))

from collections import deque
def check(n):
    s=set([int(i) for i in str(n)])
    if len(s)<=2:
        return 1
    else:
        return 0
n=int(input())
s=set()
q=deque()
q.append(0)
while(len(q)>0):
    g=q.popleft()
    if g>n:
        break
    s.add(g)
    if g>=n:
        break
    for j in range(0,10):
        if g*10+j not in s and check(g*10+j):
            q.append(g*10+j)

print(len(s)-1)

def cnt(s, p):
    ans = 0
    if p > s: ans = 0
    elif len(p) == len(s):
        ans = 1 if len(set(p.lstrip('0'))) <= 2 else 0
    elif len(set(p.lstrip('0'))) > 2: ans = 0
    elif s[:len(p)] > p:
        if len(set(p.lstrip('0'))) == 2:
            ans = 2**(len(s)-len(p))
        elif len(set(p.lstrip('0'))) == 1:
            ans = 1 + 9 * (2**(len(s)-len(p)) - 1)
        else:
            ans = 10 + 45 * (2**(len(s)-len(p)) - 2)
    else: ans = sum(cnt(s, p+c) for c in '0123456789')

    return ans

print(cnt(input().strip(), '')-1)

"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

temp = pow(10, 8)
def dfs(number):
    if 0 < number <= n:
        answer[0] += 1
    if number >= temp:
        return
    for i in range(10):
        if number * 10 + i > 0:
            if len(set(str(number * 10 + i))) <= 2:
                dfs(number * 10 + i)

n = int(data())
answer = [0]
dfs(0)
outln(answer[0])

"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

temp = pow(10, 8)

def dfs(number):
    if 0 < number <= n:
        answer[0] += 1
    if number >= temp:
        return
    for i in range(10):
        if number * 10 + i > 0:
            if len(set(str(number * 10 + i))) <= 2:
                dfs(number * 10 + i)

n = int(data())
answer = [0]
dfs(0)
if n > temp:
    outln(answer[0] + 1)
    exit()
outln(answer[0])

n = input()
a = int(n[0])
l = len(n)
d = 1 << (l - 1)

def f(a, i):
    global n, l
    if i == l: return 0
    b = int(n[i])
    i += 1
    d = 1 << (l - i)
    if a > b: return b * d + g(a, b, i)
    if a == b: return b * d + f(a, i)
    return (b - 1) * d + g(a, b, i) + 9 * (d >> 1)

def g(a, b, i):
    if i == l: return 0
    c = int(n[i])
    d = 1 << (l - i - 1)
    if a > b: a, b = b, a
    if c < a: return 0
    if c == a: return g(a, b, i + 1)
    if c < b: return d
    if c == b: return d + g(a, b, i + 1)
    return 2 * d

print(a * (9 * d - 8) + 72 * (d - l) + f(a, 1))

n=int(input())
slen=len(str(n))
MOD=10**9+7
nums=[i for i in range(1,100)]
for i in range(3,10):
    for j in range(0,10):
        for k in range(0,10):
            for z in range(0,10):
                curr=str(j)*z+str(k)*(i-z)
                nums.append(int(curr))
nums=list(set(nums))
nums=[i for i in nums if len(set(str(i)))<=2]
nums.sort()
#print(nums[0:15])
cnt=0
for i in nums:
    if i<=0:
        continue
    if i<=n:
        cnt+=1
       # print(i)
    else:
        break
print(cnt)

n=int(input())
curr=list([i for i in range(1,100)])
curr=set(curr)
def isvalid(x):
    if x<1 or x>10**9:
        return 0
    if len(set(str(x)))<=2:
        return 1
cnt=0
while cnt<=6*(10**4 ):
    curr1=set()
    for i in curr:
        for j in range(10):
            if isvalid(i*10+j):
                curr1.add(i*10+j)
               # print('hi')
                cnt+=1
    #print(curr1)
    curr|=curr1
curr=sorted(list(curr))
#print(curr)
ans=0
for i in curr:
    if i>=1 and i<=n:
        ans+=1
    elif i>n:
        break
print(ans)

n=int(input())
curr=list([i for i in range(1,100)])
curr=set(curr)
def isvalid(x):
    if x<1 or x>10**9:
        return 0
    if len(set(str(x)))<=2:
        return 1
cnt=0
while cnt<=10**4 :
    curr1=set()
    for i in curr:
        for j in range(10):
            if isvalid(i*10+j):
                curr1.add(i*10+j)
               # print('hi')
                cnt+=1
    #print(curr1)
    curr|=curr1
curr=sorted(list(curr))
#print(curr)
ans=0
for i in curr:
    if i>=1 and i<=n:
        ans+=1
    elif i>n:
        break
print(ans)

n=int(input())
curr=list([i for i in range(1,100)])
curr=set(curr)
def isvalid(x):
    if x<1 or x>10**9:
        return 0
    if len(set(str(x)))<=2:
        return 1
cnt=0
while cnt<=4*(10**4 ):
    curr1=set()
    for i in curr:
        for j in range(10):
            if isvalid(i*10+j):
                curr1.add(i*10+j)
               # print('hi')
                cnt+=1
    #print(curr1)
    curr|=curr1
curr=sorted(list(curr))
#print(curr)
ans=0
for i in curr:
    if i>=1 and i<=n:
        ans+=1
    elif i>n:
        break
print(ans)

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

n = int(input())
if n < 100:
    print(n)
    sys.exit()
a = [[_,set(map(int,list(str(_))))] for _ in range(100)]
c = 99
for k in range(2,11):
    t = (10 ** (k-1))
    for aa in a:
        if aa[0] >= t:
            break
        aa[1] |= set([0])
    for i in range(1,10):
        t = i * (10 ** k)
        for ai, ae in a[:]:
            ac = ai + t
            if ac > n:
                print(c)
                sys.exit()
            if len(ae) < 2:
                ae = ae | set([i])
            if i in ae:
                c += 1
                a.append([ac,ae])

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

n = int(input())
if n < 100:
    print(n)
    sys.exit()
a = [[_,set(map(int,list(str(_))))] for _ in range(100)]
c = 99
for k in range(2,11):
    t = (10 ** (k-1))
    for aa in a:
        if aa[0] >= t:
            break
        aa[1] |= set([0])
    at = a[:]
    for i in range(1,10):
        t = i * (10 ** k)
        for ai, ae in at:
            ac = ai + t
            if ac > n:
                print(c)
                sys.exit()
            if len(ae) < 2:
                ae = ae | set([i])
            if i in ae:
                c += 1
                a.append([ac,ae])

#!/home/kameda/pyenv2/bin/python

power2list = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
'''
If the head of n (:(len(str(n))=i) is fixed as 'x',
number of candidates trailing digit is
9*(2^(i-1)-1)+1
9: len(range(0,10) except x)
(2^(i-1)-1): number of patterns like (xxy xyx xyy) if i=3
1: number of patterns like xxx if i=3

trailing_candidates = []
for i in range(1, 11):
    trailing_candidates.append(9*(2**(i-1)-1)+1)

'''
trailing_candidates = [1, 10, 28, 64, 136, 280, 568, 1144, 2296, 4600]
'''
For each head (1..9), trailing_candidates can be applied.
So, cumulative candidates lower than 10^i is calculated as below.

cumulative_candidates = [9]
for i in range(1, 9):
    cumulative_candidates.append(9*trailing_candidates[i]+cumulative_candidates[i-1])

'''
cumulative_candidates = [9, 99, 351, 927, 2151, 4671, 9783, 20079, 40743]

def main_y_fixed(n, y):
    #Count candidates which is n or less starting with n[0] (=x) given y (!=x)
    x = n[0]
    len_n = len(n)
    uln = 0
    if len_n == 1:
        return 1
    if int(y) > int(x):
        if int(n[1]) < int(x): # e.g. 42????? given 8 -> No candidates
            pass
        elif int(n[1]) == int(x): # e.g. 44????? given 8
            uln += main_y_fixed(n[1:], y)
        elif int(n[1]) < int(y): # e.g. 47????? given 8 -> 4488888 is the largest
            uln += power2list[len_n-2]
        elif int(n[1]) == int(y): # e.g. 48????? given 8
            uln += power2list[len_n-2]
            uln += main_y_fixed(n[1:], x)
        elif int(n[1]) > int(y): # e.g. 49????? given 8 -> 4888888 is the largest
            uln += power2list[len_n-1]
    elif int(y) == int(x):
        raise ValueError('2nd argument should be different from 1st degit of 1st argument')
    elif int(y) < int(x):
        if int(n[1]) < int(y): # e.g. 82????? given 4 -> No candidates
            pass
        elif int(n[1]) == int(y): # e.g. 84????? given 4
            uln += main_y_fixed(n[1:], x)
        elif int(n[1]) < int(y): # e.g. 87????? given 4 -> 8488888 is the largest
            uln += power2list[len_n-2]
        elif int(n[1]) == int(x): # e.g. 88????? given 4
            uln += power2list[len_n-2]
            uln += main_y_fixed(n[1:], y)
        elif int(n[1]) > int(y): # e.g. 89????? given 4 -> 8888888 is the largest
            uln += power2list[len_n-1]
    return uln

def main(n):
    #Count candidates which is n or less starting with n[0] (=x)
    x = n[0]
    len_n = len(n)
    uln = 0
    if len_n == 1:
        return 1
    if int(n[1]) > 0:
        for i in range(0, int(n[1])): #int(n[0]), ~int(n[1])-1 and all trailings
            if i != int(n[0]):
                uln += power2list[len_n-2]
            else:
                uln += trailing_candidates[len_n-2]
    if len_n == 2:
        return uln+1
    if int(n[0]) < int(n[1]):
        if int(n[2]) < int(n[0]): #e.g. 482????? -> 47777777 is the largest.
            pass
        elif int(n[2]) == int(n[0]): #e.g. 484?????
            uln += main_y_fixed(n[2:], n[1])
        elif int(n[2]) < int(n[1]): #e.g. 486????? -> 48488888 is the largest.
            uln += power2list[len_n-3]
        elif int(n[2]) == int(n[1]): #e.g. 488?????
            uln += power2list[len_n-3]
            uln += main_y_fixed(n[2:], n[0])
        elif int(n[2]) > int(n[1]): #e.g. 489?????
            uln += power2list[len_n-2]
    elif int(n[0]) == int(n[1]):
        uln += main(n[1:])
    elif int(n[0]) > int(n[1]):
        if int(n[2]) < int(n[1]): #e.g. 842????? -> 83333333 is the largest.
            pass
        elif int(n[2]) == int(n[1]): #e.g. 844?????
            uln += main_y_fixed(n[2:], n[0])
        elif int(n[2]) < int(n[1]): #e.g. 846????? -> 84488888 is the largest.
            uln += power2list[len_n-3]
        elif int(n[2]) == int(n[0]): #e.g. 848?????
            uln += power2list[len_n-3]
            uln += main_y_fixed(n[2:], n[1])
        elif int(n[2]) > int(n[1]): #e.g. 849?????
            uln += power2list[len_n-2]
    return uln

if __name__ == "__main__":
    N = raw_input()
    Len_N = len(N)
    if Len_N <= 2:
        print(N)
        exit(0)
    Uln = cumulative_candidates[Len_N-2] # below 10^len_n
    Uln += (int(N[0])-1)*trailing_candidates[Len_N-1] # between 10^len_n and n[0]*10^len_n
    Uln += main(N)
    print(Uln)
    exit(0)

ans = 0
val = int(raw_input())
def fun(n):
    global val
    global ans
    if(n > 0 and n <= val):
        ans += 1
    if n >= 10**8:
        return
    for a in range(10):
        if(n*10 + a) > 0:
            if len(set((str(n*10 + a)))) <= 2:
                fun(n*10 + a)
fun(0)
print ans

n = input()

if n <= 10:
	print n
else:
	cnt = 9
	le = len(str(n))
	i = 1
	while i < le-1:
		cnt += (81*(1<<i-1) + 9)
		i += 1

	d = {}

	for i in xrange(1,10):
		d[(int(str(i)*le))] = 1

	for i in xrange(1,10):
		for j in xrange(10):
			if i != j:
				mask = 0
				while mask < (1<<le-1):
					tmp = ""
					for k in xrange(le-1):
						if (mask&(1<<k)) > 0:
							tmp = str(i) + tmp
						else:
							tmp = str(j) + tmp
					tmp = str(i) + tmp
					d[(int(tmp))] = 1
					mask += 1

	for key in d:
		if key <= n:
			cnt += 1
	print cnt

n=input()

r=0
def dfs(a):
    #print a
    r=0
    if a > 0 and a <= n: r+=1
    if a > n or a > 10**8: return r
    for d in range(10):
        #print d,len(set(str(a*10+d))),a*10+d
        if len(set(str(a*10+d))) < 3 and a*10+d:
            r+=dfs(a*10+d)
    return r
if n == 10**9:r+=1
r+=dfs(0)
print r

'''

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advices/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.

'''

import math
count = 0
n = 0
def distinct_digits(a):
	d= {}
	for i in a:
		d[i] = 1
	return len(d)

def fn(num):
	global count, n
	if (num > 0 and num <= n):
		count+=1
	if (num >= 10**8):
		return
  	for a  in range(0, 10):
    		if num*10+a > 0 and distinct_digits(str( num*10+a )) <= 2:
			        fn( num*10+a )

if __name__ == '__main__':
	n=input()
	fn(0)
	print count

####################################################
# -*- coding: utf-8 -*-
import sys

w = sys.stdout.write
read = sys.stdin.readline
reads = sys.stdin.read

def r(f=None):
    if f:
        return map(f, read().split())
    else:
        return read().split()

def rs(t,f=None):
    result = []
    result_append = result.append
    for i in xrange(t):
        if f:
            result_append(tuple(map(f, read().split())))
        else:
            result_append(list(read().split()))
    return result

####################################################
import math
sqrt = math.sqrt
from collections import deque

[n] = r(int)

res = 0
for x, y in [(x, y) for x in range(10) for y in range(10) if x < y]:
    x = str(x)
    y = str(y)
    for b in xrange(2**9+1):
        bb = int(str(bin(b)).replace('0b', '').replace('1', x).replace('0', y))
        if bb <= n:
            res += 1
for x in range(10):
    for i in range(1, 10):
        if int("".join([str(x)] * i)) <= n:
            res += 1

w(str(res))

import sys

n = int(raw_input()) + 1
ans = 0
tmp = []
def dfs(num, x, y, inx, iny):
  global ans
  if num < n and inx and iny :
    ans += 1
    tmp.append(num)
  if num > n:
    return
  if x or num :
    if num*10 + x < n:
      dfs(num*10 + x, x, y, 1, iny)
  if y or num :
    if num*10 + y < n:
      dfs(num*10 + y, x, y,inx, 1)

for x in range(0,10):
  for y in range(x + 1, 10):
    if x:
      dfs(y, x, y, 0, 1)
    dfs(x, x, y, 1, 0)
print ans
print len(tmp), sorted(tmp)

import sys

n = int(raw_input())
ans = 0
def dfs(num, x, y, inx, iny):
  global ans
  if num < n and inx and iny :
    ans += 1
  if num > n:
    return
  if x or num :
    if num*10 + x < n:
      dfs(num*10 + x, x, y, 1, iny)
  if y or num :
    if num*10 + y < n:
      dfs(num*10 + y, x, y,inx, 1)

for x in range(0,10):
  for y in range(x + 1, 10):
    if x:
      dfs(y, x, y, 0, 1)
    dfs(x, x, y, 1, 0)
print ans

import sys

n = int(raw_input())
ans = 0
def dfs(num, x, y, inx, iny):
  global ans
  if num < n and inx and iny :
    ans += 1
  if num > n:
    return
  if x or num :
    if num*10 + x < n:
      dfs(num*10 + x, x, y, 1, iny)
  if y or num :
    if num*10 + y < n:
      dfs(num*10 + y, x, y,inx, 1)

for x in range(0,10):
  for y in range(x + 1, 10):
    dfs(y, x, y, 0, 1)
    if x:
      dfs(x, x, y, 1, 0)
print ans

n=input()
st=set()
def dfs(x,l):
    if l>=10 or x>n:return
    if x: st.add(x)
    dfs(10*x+a,l+1)
    dfs(10*x+b,l+1)

for a in xrange(10):
    for b in xrange(a+1,10):
        dfs(0,0)
print len(st)

n=input()
ans=set()

def dfs(p,l):
    if p>n or l>=10:
        return
    if p>0:
        ans.add(p)
    dfs(p*10+a,l+1)
    dfs(p*10+b,l+1)

for a in range(0,10):
    for b in range(0,a):
        dfs(0,0)
print "%d" % len(ans)

n=int(raw_input())
if n<102:
    print n
else:
    arr=set([])
    for i in range(1,100):
        arr.add(i)
    for i in range(10,101):
        x=str(i/10)
        y=str(i%10)
        a=str(i)
        done =False

        while not done:

            if x==y:
                for k in range(0,10):
                    if int(x)!=k:
                        newx=a+str(k)
                        if int(newx)<=n:
                            arr.add(int(newx))

            new2=a+x

            if int(new2)<=n:
                arr.add(int(new2))
            new3=a+y
            if int(new3)<=n:
                arr.add(int(new3))
            new1=a+str(i)
            if int(new1)<=n:
                arr.add(int(new1))
            else:
                done=True
            a=a+str(i)
    #arr=list(arr)
    #arr.sort()
    #print arr
    print len(arr)

n=int(raw_input())
if n<102:
    print n
else:
    arr=set([])
    for i in range(1,100):
        arr.add(i)
    for i in range(10,100):
        x=str(i/10)
        y=str(i%10)
        a=str(i)
        done =False

        while not done:
            if x==y:
                for k in range(0,10):
                    if int(x)!=k:
                        newx=a+str(k)
                        if int(newx)<=n:
                            arr.add(int(newx))

            new2=a+x

            if int(new2)<=n:
                arr.add(int(new2))
            new3=a+y
            if int(new3)<=n:
                arr.add(int(new3))
            new1=a+str(i)
            if int(new1)<=n:
                arr.add(int(new1))
            else:
                done=True
            a=a+str(i)
    #arr=list(arr)
    #arr.sort()
    #print arr
    print len(arr)

n=int(raw_input())
arr=set([])
for i in range(1,100):
    arr.add(i)
for i in range(10,100):
    x=str(i/10)
    y=str(i%10)
    a=str(i)
    done =False
    while not done:
        if x==y:
            for k in range(0,10):
                newx=a+str(k)
                if int(newx)<=n:
                    arr.add(int(newx))

        new2=a+x

        if int(new2)<=n:
            arr.add(int(new2))
        new3=a+y
        if int(new3)<=n:
            arr.add(int(new3))
        new1=a+a
        if int(new1)<=n:
            arr.add(int(new1))
        else:
            done=True
        a=a+a
#arr=list(arr)
#arr.sort()
#print arr
if n<99:
    print n
else:
    print len(arr)

n=int(input())
array=set()
array.add(10**9)
for x in range(10):
    for y in range(10):
        for l in range(1, 9):
            for m in range(1, 2 ** l + 1):
                s = [str(x) if m & (1 << i) else str(y) for i in range(l)]
                u = int(''.join(s))
                if u <= n:
                    array.add(u)
array.remove(0)
# print (sorted(list(array)))
array=[u for u in array if u <= n]
print(len(array))

n=int(input())
array=set()
array.add(10**9)
for x in range(10):
    for y in range(10):
        for l in range(1, 9):
            for m in range(1, 2 ** l + 1):
                s = [str(x) if m & (1 << i) else str(y) for i in range(l)]
                u = int(''.join(s))
                if u <= n:
                    array.add(u)
# print (sorted(list(array)))
print(len(array))

from collections import deque
def check(n):
    s=set([int(i) for i in str(n)])
    if len(s)<=2:
        return 1
    else:
        return 0
n=int(input())
s=set()
q=deque()
q.append(0)
while(len(q)>0):
    g=q.popleft()
    if g>=n:
        break
    s.add(g)
    if g>=n:
        break
    for j in range(0,10):
        if g*10+j not in s and check(g*10+j):
            q.append(g*10+j)

print(len(s)-1)