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


public class B136 {	
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

	public void solve() throws IOException {
		int X = nextInt();
		
		int to = (int) Math.sqrt(X);
		boolean[] digits = new boolean[10];
		
		int tmp = X;
		while(tmp > 0){
			digits[tmp % 10] = true;	
			tmp /= 10;
		}
		int ans = 0;
		for(int i = 1; i <= to; i++){
			if( X % i == 0 ){
				int tmp2 = i;
				wh: while( tmp2 > 0 ){
					if( digits[tmp2 % 10] ){
						ans++;				
						break wh;
					}
					tmp2 /= 10;
				}
				
				tmp2 = X / i;
				if( tmp2 != i)
					wh: while( tmp2 > 0 ){
						if( digits[tmp2 % 10] ){
							ans++;				
							break wh;
						}
						tmp2 /= 10;
					}
			}
		}
		out.println( ans );
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new B136().run();
	}
	
	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}
