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;

/**
 * 
 */

/**
 * @author antonio081014
 * @time: Jul 23, 2012, 9:47:49 AM
 */
public class B {

    public static void main(String[] args) throws Exception {
	B main = new B();
	main.run();
	System.exit(0);
    }

    public void run() throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int x = Integer.parseInt(br.readLine());
	if (x == 1) {
	    System.out.println(1);
	    return;
	}
	String strX = Integer.toString(x);
	int count = 0;
	for (int i = 1; i <= (int) Math.sqrt(1.0 * x); i++) {
	    if (x % i == 0) {
		if (check(strX, i))
		    count++;
		if ((i != x / i) && check(strX, x / i))
		    count++;
	    }
	}
	System.out.println(count);
    }

    public boolean check(String x, int a) {
	String strA = Integer.toString(a);
	// for (int i = 0; i < Math.min(x.length(), strA.length()); i++)
	// if (x.charAt(i) == strA.charAt(i))
	// return true;
	for (int i = 0; i < x.length(); i++)
	    for (int j = 0; j < strA.length(); j++)
		if (x.charAt(i) == strA.charAt(j))
		    return true;
	return false;
    }
}
