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.BufferedInputStream;
import java.util.*;
import static java.lang.Math.*;

public class C221B {

	public void solve() throws Exception {
		int n = nextInt();
		HashSet<Integer> digits = new HashSet<Integer>();
		int N = n;
		while(N > 0) {
			digits.add(N % 10);
			N /= 10;
		}
		int res = 0;
		for (int i = 1; i * i <= n; i++) {
			if (n % i != 0) {
				continue;
			}
			if (ok(i, digits)) {
				res++;
			}
			if (ok(n / i, digits) && n / i != i) {
				res++;
			}
			
		}
		println(res);
	}
	
	boolean ok(int a, HashSet<Integer> digits) {
		while (a > 0) {
			int digit = a % 10;
			if (digits.contains(digit)) {
				return true;
			}
			a /= 10;
		}
		return false;
	}

	// ------------------------------------------------------

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(Object... os) {
		if (os != null && os.length > 0)
			System.out.print(os[0].toString());
		for (int i = 1; i < os.length; ++i)
			System.out.print(" " + os[i].toString());
	}

	void println(Object... os) {
		print(os);
		System.out.println();
	}

	BufferedInputStream bis = new BufferedInputStream(System.in);

	String nextWord() throws Exception {
		char c = (char) bis.read();
		while (c <= ' ')
			c = (char) bis.read();
		StringBuilder sb = new StringBuilder();
		while (c > ' ') {
			sb.append(c);
			c = (char) bis.read();
		}
		return new String(sb);
	}

	String nextLine() throws Exception {
		char c = (char) bis.read();
		while (c <= ' ')
			c = (char) bis.read();
		StringBuilder sb = new StringBuilder();
		while (c != '\n' && c != '\r') {
			sb.append(c);
			c = (char) bis.read();
		}
		return new String(sb);
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextWord());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextWord());
	}
	
	public static void main(String[] args) throws Exception {
		new C221B().solve();
	}
}
