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.

Input

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

Output

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

Examples

Input

10


Output

10


Input

123


Output

113

Note

In 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.
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.util.zip.*;

@SuppressWarnings("unchecked")
public class P244B {

  final static String DIFFs =
    "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";

  public void run() throws Exception {
    DataInputStream dis =
      new DataInputStream(
        new GZIPInputStream(
          new ByteArrayInputStream(Base64.getDecoder().decode(DIFFs))));

    int k = 1, n = 1, nn = nextInt();
    for (int d = 0; n < nn; k++, n += d, d = 0) {
      for (int s = 0, b = 0; b <= 0; b = dis.readByte(), d |= (b & 0x7f) << s, s += 7);
    }

    println(k - Integer.signum(n - nn));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P244B().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  long gcd(long a, long b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }
}