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.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class B {
    private static BufferedReader in;
    private static StringTokenizer st;
    private static PrintWriter out;
    
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int x = nextInt();
        int cnt = 0;
        for (int i = 1; i <=Math.sqrt(x) + 1e-8; i++) {
            if(x % i ==0){
                if(haveCommonDigit(i,x)) cnt ++;
                if(x/i != i && haveCommonDigit(x/i,x)) cnt ++;
            }
        }
        System.out.println(cnt);
    }
    private static boolean haveCommonDigit(int i, int x) {
        boolean digit[] = new boolean [10];
        String s = x+"";
        for (int j = 0; j < s.length(); j++) {
            digit[s.codePointAt(j)-48] = true;
        }
        s = i+"";
        for (int j = 0; j < s.length(); j++) {
            if(digit[s.codePointAt(j)-48])
                return true;
        }
        return false;
        
    }
    static String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
    static int nextInt() throws NumberFormatException, IOException{
        return Integer.parseInt(next());
    }
    static long nextLong() throws NumberFormatException, IOException{
        return Long.parseLong(next());
    }
    
    static double nextDouble() throws NumberFormatException, IOException{
        return Double.parseDouble(next());
    }

}
