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

/**
 *
 * @author tendua Sep 1, 2012 2:07:33 AM
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class cf136b implements Runnable {

    private void solve() throws IOException {
        int n = ni();
        if (n==1 || n==2){
            System.out.println("1");
            return;
        }
        int limit = (int) Math.ceil(Math.sqrt(n));
        int counter = 0;
        String num = String.valueOf(n);

        for (int I = 1; I <= limit; I++) {
            if (n % I == 0) {
                if (comp(String.valueOf(I), num) == true) {
                    counter++;
                }
                if ((I != (n / I)) && comp(String.valueOf(n / I), num) == true) {
                    counter++;
                }
            }
        }
        System.out.println(counter);
    }

    private static boolean comp(String a, String b) {
        int la = a.length();
        int lb = b.length();
        for (int I = 0; I < la; I++) {
            for (int J = 0; J < lb; J++) {
                if (a.charAt(I) == b.charAt(J)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        new cf136b().run();
    }
    BufferedReader br;
    StringTokenizer st;
    PrintWriter pw;

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            st = null;
            pw = new PrintWriter(System.out);
            solve();
            br.close();
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

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