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.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Problem implements Runnable {
    public static void main(String[] args) {
        new Problem().run();
    }
    
    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    
    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;
    
    String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens())
            in = new StringTokenizer(br.readLine());
        return in.nextToken();
    }
    
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    
    boolean haveCommonNumber(String a, int b) {
        String x = String.valueOf(b);
        for (int i = 0; i < a.length(); i++)
            for (int j = 0; j < x.length(); j++)
                if (x.charAt(j) == a.charAt(i))
                    return true;
        return false;
    }
    
    void solve() throws IOException {
        int x = nextInt();
        if (x == 2) {
            out.print(1);
            return;
        }
        String a = String.valueOf(x);
        int ans = 0;
        for (int i = 1; i < Math.sqrt(x) + 1; i++) {
            if (x % i != 0)
                continue;
            if (haveCommonNumber(a, i))
                ans++;
            if (haveCommonNumber(a, x / i) && i != x / i)
                ans++;
        }
        out.print(ans);
    }
    
    public void run() {
        try {
            long startTime = System.currentTimeMillis();
            Locale.setDefault(Locale.US);
            
            if (!ONLINE_JUDGE) {
                br = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
                solve();
            } else {
                br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
                solve();
            }
            out.close();
            br.close();
            
            long endTime = System.currentTimeMillis();
            long freeMemory = Runtime.getRuntime().freeMemory();
            long totalMemory = Runtime.getRuntime().totalMemory();

            System.err.printf("Time = %.3f s\n", (endTime - startTime) / 1000.0);
            System.err.printf("Memory = %.3f MB\n", (totalMemory - freeMemory) / (float)(1 << 20));
            
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}