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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    int x;
    boolean[] d = new boolean[10];

    boolean check(int n) {
        String ns = n + "";
        for (int i = 0; i < ns.length(); i++)
            if (d[ns.charAt(i) - '0'])
                return true;
        return false;
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        x = in.nextInt();
        String xs = x + "";
        for (int i = 0; i < xs.length(); i++)
            d[xs.charAt(i) - '0'] = true;
        int ret = 0;
        for (int i = 1; i * i <= x; i++)
            if (x % i == 0) {
                if (i * i == x) {
                    if (check(i))
                        ret++;
                } else {
                    if (check(i))
                        ret++;
                    if (check(x / i))
                        ret++;
                }
            }
        out.println(ret);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

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

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
}
