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.util.*;
import java.io.*;

public class Codeforces {
	public static void main (String[] args) throws IOException {
		BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
		//StringTokenizer tokenizer = new StringTokenizer (reader.readLine());
		int x = Integer.parseInt(reader.readLine());
		ArrayList<Integer> divisors = findDivisor(x);
		int counter = 0;
		int limit = divisors.size();
		for (int ii = 0; ii < limit; ii++) {
			int checkthis = divisors.get(ii);
			if (check (checkthis, x)) {
				counter++;
			}
		}
		System.out.println (counter);
	}
	
	public static ArrayList<Integer> findDivisor (int x) {
		ArrayList<Integer> divisors = new ArrayList<Integer>();
		int limit = (int) Math.sqrt (x);
		for (int ii = 1; ii <= limit; ii++) {
			if (x % ii == 0) {
				divisors.add (ii);
				divisors.add (x / ii);
			}
		}
		if (limit * limit == x) divisors.remove (divisors.size() - 1);
		return divisors;
	}
	
	public static boolean check (int x, int y) {
		String a = String.valueOf (x);
		String b = String.valueOf (y);
		boolean[] checkA = new boolean[10];
		boolean[] checkB = new boolean[10];
		for (int ii = 0; ii < a.length(); ii++) {
			checkA[a.charAt(ii) - '0'] = true;
		}
		for (int ii = 0; ii < b.length(); ii++) {
			checkB[b.charAt(ii) - '0'] = true;
		}
		for (int ii = 0; ii < 10; ii++) {
			if (checkA[ii] && checkB[ii]) {
				return true;
			}
		}
		return false;
	}
}