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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader reader = new FastReader();
		int x = reader.nextInt();
		reader.close();
		int[] f = new int[10];
		for (char c : String.valueOf(x).toCharArray())
			++f[c - '0'];
		int val = (int) Math.sqrt((double) x);
		int cnt = 0;
		outer: for (int i = 1; i <= val; ++i) {
			if (x % i == 0) {
				int v1 = i;
				int v2 = x / i;
				int[] f1 = new int[10];
				for (char c : String.valueOf(v1).toCharArray())
					++f1[c - '0'];
				if (v1 == v2) {
					for (int j = 0; j < 10; ++j)
						if (f[j] > 0 && f1[j] > 0) {
							++cnt;
							continue outer;
						}
					break;
				}
				int[] f2 = new int[10];
				for (char c : String.valueOf(v2).toCharArray())
					++f2[c - '0'];
				boolean first = false;
				boolean second = false;
				for (int j = 0; j < 10; ++j) {
					if (f[j] > 0 && f1[j] > 0)
						first = true;
					if (f[j] > 0 && f2[j] > 0)
						second = true;
					if (first && second) {
						cnt += 2;
						continue outer;
					}
				}
				cnt += first || second ? 1 : 0;
			}
		}
		System.out.println(cnt);
	}

	public static void print2D(int[][] mat) {
		StringBuilder sb = new StringBuilder("");
		for (int i = 0; i < mat.length; ++i) {
			for (int j = 0; j < mat[i].length; ++j)
				sb.append(mat[i][j] + " ");
			sb.append("\n");
		}
		System.out.println(sb.toString().trim());
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine().trim());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			StringBuilder str = new StringBuilder("");
			try {
				str.append(br.readLine().trim());
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str.toString();
		}

		int[] readArray(int size) {
			int[] ar = new int[size];
			for (int i = 0; i < size; ++i)
				ar[i] = nextInt();
			return ar;
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}