#include <bits/stdc++.h>
int A[10000009], B[20];
void make(long long h1, int h2, int h3, int h4) {
  if (h1 <= 1000000000) {
    if (h4 == 1) A[h1 / 100]++;
    make(h1 * 10 + h2, h2, h3, h4);
    if (h2 != h3) make(h1 * 10 + h3, h2, h3, 1);
  }
}
int main() {
  int i, j, n, cnt, t, ii, cc;
  for (i = 1; i <= 9; i++) {
    make(i, i, i, 1);
    make(i, i, 0, 0);
  }
  for (i = 1; i <= 9; i++) {
    for (j = i + 1; j <= 9; j++) {
      make(i, i, j, 0);
      make(j, j, i, 0);
    }
  }
  for (i = 1; i <= 10000000; i++) A[i] += A[i - 1];
  while (scanf("%d", &n) == 1) {
    cnt = 0;
    if (n / 100 - 1 >= 0) cnt += A[n / 100 - 1];
    t = (n / 100) * 100;
    if (t < 1) t = 1;
    for (i = t; i <= n; i++) {
      for (j = 0; j < 10; j++) B[j] = 0;
      ii = i;
      cc = 0;
      while (ii != 0) {
        if (B[ii % 10] == 0) {
          B[ii % 10] = 1;
          cc++;
        }
        ii /= 10;
        if (cc > 2) break;
      }
      if (cc <= 2) cnt++;
    }
    printf("%d\n", cnt);
  }
  return 0;
}
