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.*;
import java.math.*;

public class contest136B implements Runnable {

    
    public void run() {
        int x = nextInt();
        int count = 0;
        for (int i = 1; i <= Math.sqrt(x) ; i++) {
            if(x%i == 0){
                if(compare(x, i)) {
                
                    count ++;
                }
                if(i * i != x){
                    if(compare(x, x/i)){
                        
                        count ++;
                    }
                }
            }   
        }
        
        System.out.println(count);

        
        
        
        
//      -----------------------------------------------------------------------------------

        out.close();
        System.exit(0);
    }
    
  private boolean   compare(int a, int b){
        Set<Character> set = new HashSet<Character>();
        String str = a+"";
        for (int i = 0; i < str.length(); i++) {
            set.add(str.charAt(i));
            
        }
        
        String str2 = b+"";
        for (int i = 0; i < str2.length(); i++) {
            if(set.contains(str2.charAt(i))) return true;
        }
        
        return false;

    
    }
    

    
    private static boolean fileIOMode;
    private static String problemName = "xxx";
    private static BufferedReader in;
    private static PrintWriter out;
    private static StringTokenizer tokenizer;

    public static void main(String[] args) throws Exception {
        fileIOMode = false;
        if (fileIOMode) {
            in = new BufferedReader(new FileReader(problemName + ".in"));
            out = new PrintWriter(problemName + ".out");
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        tokenizer = new StringTokenizer("");

        new Thread(new contest136B()).start();
    }

    private static String nextLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    private static String nextToken() {
        while (!tokenizer.hasMoreTokens()) {
            String str = nextLine();
            if(str==null) return null;
            tokenizer = new StringTokenizer(str);
        }
        return tokenizer.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    private static long nextLong() {
        return Long.parseLong(nextToken());
    }

    private static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    private static BigInteger nextBigInteger() {
        return new BigInteger(nextToken());
    }

    private static void print(Object o) {
        if (fileIOMode) {
            System.out.print(o);
        }
        out.print(o);
    }

    private static void println(Object o) {
        if (fileIOMode) {
            System.out.println(o);
        }
        out.println(o);
    }

    private static void printf(String s, Object... o) {
        if (fileIOMode) {
            System.out.printf(s, o);
        }
        out.printf(s, o);
    }
}

