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 static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.Line2D;
import java.awt.Point;
import static java.lang.reflect.Array.*;

public class B {

    boolean DEBUG = true;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder out = new StringBuilder();
    StringTokenizer st = null;

    String s() throws IOException {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int i() throws IOException {
        return Integer.parseInt(s());
    }

    int i(String s) throws IOException {
        return Integer.parseInt(s);
    }

    long l() throws IOException {
        return Long.parseLong(s());
    }

    long l(String s) throws IOException {
        return Long.parseLong(s);
    }

    double d() throws IOException {
        return Double.parseDouble(s());
    }

    double d(String s) throws IOException {
        return Double.parseDouble(s);
    }

    void D(Object a) {
        if (DEBUG) {
            int len = getLength(a);
            for (int i = 0; i < len; ++i) {
                System.out.print(get(a, i) + " ");
            }
            System.out.println();
        }
    }

    void D(Object[] a) {
        if (DEBUG) {
            int R = getLength(a), C = getLength(get(a, 0));
            for (int i = 0; i < R; ++i) {
                for (int j = 0; j < C; ++j) {
                    System.out.print(get(get(a, i), j) + " ");
                }
                System.out.println();
            }
        }
    }

    void D(String args) {
        if (DEBUG) {
            System.out.print(args);
        }
    }

    void D(String format, Object... args) {
        if (DEBUG) {
            System.out.printf(format, args);
        }
    }

    void fl() {
        System.out.print(out);
    }

    int x = i();
    public B() throws IOException {
        long res = 0;
        boolean[] n = new boolean[10];
        String xStr = String.valueOf(x);
        for (int i = 0; i < xStr.length(); ++i) {
            n[xStr.charAt(i) - '0'] = true;
        }
        for (int i = 1; i <= sqrt(x); ++i) {
            if(x % i == 0) {
                String iStr = String.valueOf(i);
                for (int j = 0; j < iStr.length(); ++j) {
                    if(n[iStr.charAt(j) - '0']) {
                        //System.out.println(i);
                        ++res;
                        break;
                    }
                }
                int newI = x / i;
                if(newI == i) {
                    continue;
                }
                iStr = String.valueOf(newI);
                for (int j = 0; j < iStr.length(); ++j) {
                    if(n[iStr.charAt(j) - '0']) {
                        //System.out.println(newI);
                        ++res;
                        break;
                    }
                }
            }
        }
        out.append(res).append("\n");
        fl();
    }

    public static void main(String[] args) throws IOException {
        new B();
    }
}
