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;
const int INF = 1000000001;
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
  return out << p.first << ' ' << p.second;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {
    out << *i << ' ';
  }
  return out;
}
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &p) {
  return in >> p.first >> p.second;
}
template <class T>
istream &operator>>(istream &in, vector<T> &v) {
  for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {
    in >> (*i);
  }
  return in;
}
template <class T>
ostream &operator,(ostream &out, const T &t) {
  return out << t;
}
template <class T>
istream &operator,(istream &in, T &t) {
  return in >> t;
}
int io_init() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout, fixed, setprecision(9);
  return 1;
}
int _io_dummy = io_init();
template <class T, class U>
bool remin(T &a, const U &b) {
  return b < a ? a = b, true : false;
}
template <class T, class U>
bool remax(T &a, const U &b) {
  return b > a ? a = b, true : false;
}
string toString(int x) {
  ostringstream oss;
  oss, x;
  return oss.str();
}
int main() {
  int x;
  cin, x;
  int mx = sqrt(x) + 1;
  string s = toString(x), r;
  {
    sort((s).begin(), (s).end());
    (s).resize(unique((s).begin(), (s).end()) - (s).begin());
  };
  set<int> S;
  for (int i = (1); i <= (mx); ++i) {
    if (x % i) continue;
    r = toString(i);
    {
      sort((r).begin(), (r).end());
      (r).resize(unique((r).begin(), (r).end()) - (r).begin());
    };
    int sum = ((int)(s).size()) + ((int)(r).size());
    r += s;
    {
      sort((r).begin(), (r).end());
      (r).resize(unique((r).begin(), (r).end()) - (r).begin());
    };
    if (sum != ((int)(r).size())) {
      S.insert(i);
    }
    int j = x / i;
    if (j == i) continue;
    r = toString(j);
    {
      sort((r).begin(), (r).end());
      (r).resize(unique((r).begin(), (r).end()) - (r).begin());
    };
    sum = ((int)(s).size()) + ((int)(r).size());
    r += s;
    {
      sort((r).begin(), (r).end());
      (r).resize(unique((r).begin(), (r).end()) - (r).begin());
    };
    if (sum != ((int)(r).size())) {
      S.insert(j);
    }
  }
  cout, ((int)(S).size()), '\n';
}
