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.util.Arrays.deepToString;

import java.io.*;
import java.util.*;

public class B {

    static boolean hasSameNumber(int a, int b){
        char[] a1 = String.valueOf(a).toCharArray();
        char[] b1 = String.valueOf(b).toCharArray();
        for(int i = 0; i < a1.length; i++){
            for(int j = 0; j < b1.length; j++){
                if(a1[i] == b1[j]){
                    return true;
                }
            }
        }
        return false;
    }
//  40 
//  20 4 10 
//  50 
//  5 10 25 50 
    static void solve() throws Exception {
        int x = nextInt();
        int num = x;
        int count = 0;
//      int count2 = 0;
//      for(int i = 1; i <= num; i++){
//          if(num % i == 0 && hasSameNumber(num, i)){
//              count2++;
//          }
//      }
//      System.out.println(count2);
////        1 10 100
////        50 20 
        for (int i = 1; i <= Math.sqrt(num); i++) {
            if (num % i != 0) {
                continue;
            }
            if(hasSameNumber(num, i))
                count++;            
            if (i * i != num && hasSameNumber(num, num / i)) count++;
        }
        System.out.print(count);
    }

    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static void debug(Object... a) {
        System.err.println(deepToString(a));
    }

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

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

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

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

    public static void main(String[] args) {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            solve();
            br.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}