The Little Elephant loves numbers. 

He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations. 

Help the Little Elephant to find the described number.

Input

A single line contains a single integer x (1 ≤ x ≤ 109).

Output

In a single line print an integer — the answer to the problem.

Examples

Input

1


Output

1


Input

10


Output

2
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
string toBin(long long a) {
  string res = "";
  while (a) {
    res += char((a & 1) + '0');
    a >>= 1;
  }
  reverse(res.begin(), res.end());
  return res;
}
const int mod = 1e9 + 7;
long long expo(long long base, long long pow) {
  long long ans = 1;
  while (pow != 0) {
    if (pow & 1 == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base *= base;
    base %= mod;
    pow /= 2;
  }
  return ans;
}
long long inv(long long x) { return expo(x, mod - 2); }
bool isPal(string ss) {
  int len = ss.length();
  for (int i = 0; i < len / 2; i++) {
    int comp = len - i - 1;
    if (ss[i] != ss[comp]) return false;
  }
  return true;
}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
const int M = 100001;
int arr[11];
bool is(int s) {
  if (arr[s] == 1) return true;
  return false;
}
int main() {
  long long n;
  scanf("%lld", &(n));
  long long as = n;
  int c;
  while (as) {
    c = as % 10;
    as /= 10;
    arr[c] = 1;
  }
  int ans = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i != 0) continue;
    long long temp = i;
    while (temp) {
      c = temp % 10;
      temp /= 10;
      if (is(c)) {
        ans++;
        break;
      }
    }
    if (i * i == n) continue;
    temp = n / i;
    while (temp) {
      c = temp % 10;
      temp /= 10;
      if (is(c)) {
        ans++;
        break;
      }
    }
  }
  cout << ans;
}
