#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 2000000000;
const long long i64_inf = 1000000000000000000LL;
const double pi = acos(-1.0);
using namespace std;
long long dp[10];
int n;
long long ans = 0;
int d(int a) {
  if (a <= 9) return a;
  int sum = 0;
  while (a != 0) sum += a % 10, a /= 10;
  return d(sum);
}
long long solve(int a) {
  long long A = a;
  int sa = d(A);
  long long res = 0;
  for (int sb = 1; sb <= 9; sb++) res += dp[d(sa * sb)] * dp[sb];
  long long l = 1ll;
  long long r = n + 1;
  while (l != r - 1) {
    long long m = (l + r) >> 1ll;
    if (A * m <= n)
      l = m;
    else
      r = m;
  }
  res -= l;
  return res;
}
int main() {
  cin >> n;
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) dp[d(i)]++;
  for (int i = 1; i <= n; i++) ans += solve(i);
  cout << ans << endl;
  return 0;
}
