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.util.*;

public class B {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    int n;
    static final int oszt = 1000000007;

    void solve() throws IOException {

        n = /*100;//*/ nextInt();
        int ans = 0;
        kovszam:
        for (int i = (int) Math.sqrt(n); i > 0; i--) {
            if (n % i == 0) {
                int si = i;
                boolean b = true;
                while (si > 0 && b) {
                    int s2i = si % 10;
                    si /= 10;
                    int sn = n;
                    while (sn > 0 && b) {
                        int s2n = sn % 10;
                        sn /= 10;
                        if (s2n == s2i) {
                            ans++;
                            b = false;
                        }
                    }
                }


                si = n / i;
                if (si == i) {
                    continue;
                }
                while (si > 0) {
                    int s2i = si % 10;
                    si /= 10;
                    int sn = n;
                    while (sn > 0) {
                        int s2n = sn % 10;
                        sn /= 10;
                        if (s2n == s2i) {
                            ans++;
                            continue kovszam;
                        }
                    }
                }
            }
        }
        if (n == 1) {
            out.print(1);
        } else {
            out.print(ans);
        }
    }

    void inp() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

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

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "0";
            }
        }
        return st.nextToken();
    }

    String nextString() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "0";
            }
        }
        return st.nextToken("\n");
    }

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

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

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