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

public class CodeForces {
    static boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    int test(int x) {
        int res = 0;
        if (x == 1)
            res = 1;
        else {
            res = 1;
            boolean[] digs = new boolean[10];
            int t = x;
            while (t > 0) {
                digs[t % 10] = true;
                t /= 10;
            }
            if (digs[1])
                ++res;
            for (int i = 2; i <= Math.sqrt(x); ++i) {
                if (x % i > 0)
                    continue;
                boolean OK = false;
                t = i;
                while (t > 0) {
                    if (digs[t % 10]) {
                        OK = true;
                        break;
                    }
                    t /= 10;
                }
                if (OK) {
                    ++res;
                    //out.println(i);
                }
                t = x / i;
                OK = false;
                if (t != i)
                    while (t > 0) {
                        if (digs[t % 10]) {
                            OK = true;
                            break;
                        }
                        t /= 10;
                    }
                if (OK) {
                    ++res;
                    //out.println(i);
                }
            }
        }
        return res;
    }

    void runCase(int caseNum) throws IOException {
        int x = nextInt();
        int res = test(x);

        out.println(res);

    }


    public static void main(String[] args) throws IOException {
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
        new CodeForces().runIt();
        out.flush();
        out.close();
        return;
    }

    static BufferedReader in;
    private StringTokenizer st;
    static PrintWriter out;

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line, " ");
        }
        return st.nextToken();
    }

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

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

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


    void runIt() throws IOException {
        st = new StringTokenizer("");

//        int N = nextInt();
//        for (int i = 0; i < N; i++) {
//            runCase(i + 1);
//        }
        runCase(0);

        out.flush();
    }

}
