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;
struct Point {
  int val;
  int index;
  Point() {}
  void display() {}
};
struct TimeFormat {
  int hour;
  int minute;
  TimeFormat() {}
  void display() {
    cout << hour << ":";
    if (minute < 10) {
      cout << "0" << minute;
    } else
      cout << minute;
  }
};
struct Appointment {
  TimeFormat start;
  TimeFormat end;
  string name;
  Appointment() {}
};
TimeFormat dist(TimeFormat a, TimeFormat b) {
  int minutea = a.hour * 60 + a.minute;
  int minuteb = b.hour * 60 + b.minute;
  int d = minuteb - minutea;
  TimeFormat ret;
  ret.hour = d / 60;
  ret.minute = d % 60;
  return ret;
}
bool cmpTimeFormat(TimeFormat a, TimeFormat b) {
  if (a.hour != b.hour) {
    return a.hour < b.hour;
  }
  return a.minute < b.minute;
}
bool cmpAppointment(Appointment a, Appointment b) {
  return cmpTimeFormat(a.start, b.start);
}
bool cmpPoint(Point a, Point b) {
  if (a.val != b.val) {
    return a.val < b.val;
  }
  return a.index < b.index;
}
int myabs(int x) { return x < 0 ? -x : x; }
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
bool isNum(char xx) { return ('0' <= xx && xx <= '9'); }
bool isCharacter(char xx) {
  return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
bool isUpper(char xx) { return ('A' <= xx && xx <= 'Z'); }
bool isLower(char xx) { return ('a' <= xx && xx <= 'z'); }
bool isPalin(string x) {
  int len = x.length();
  for (int i = 0; i <= len / 2; ++i) {
    if (x[i] != x[len - 1 - i]) return false;
  }
  return true;
}
bool cmp(char x, char y) {
  char xx = tolower(x);
  char yy = tolower(y);
  if (xx == yy) {
    return x < y;
  }
  return xx < yy;
}
long long val(long long x) {
  if (x < 0) return -x;
  return x;
}
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
const int maxn = 1e5 + 2;
int x;
void readEachTest() {}
void initEachTest() {}
void solveEachTest() {}
bool check(int a, int b) {
  int xa = 0, xb = 0;
  while (a > 0) {
    xa = xa | 1 << (a % 10);
    a /= 10;
  }
  while (b > 0) {
    xb = xb | 1 << (b % 10);
    b /= 10;
  }
  return ((xa & xb) != 0);
}
void read() {
  scanf("%d", &x);
  int ans = 0;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      int k = x / i;
      if (check(i, x)) ans++;
      if (k != i && check(k, x)) ans++;
    }
  }
  cout << ans;
}
void init() {}
void solve() {}
int main() {
  read();
  init();
  solve();
  return 0;
}
