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.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.lang.Integer.*;
import static java.lang.System.*;

public class Main {
   
    static InputReader in;   
    
    public static void main(String[] args) throws IOException{        
        File file = new File("input.txt");
        if(file.exists())in = new InputReader(new FileInputStream(file));
        else in = new InputReader(System.in);
        
        int x = in.nextInt(), limit = (int)(sqrt(x)), ans = 0, div;
        String n1, n2, num = x+"";
        Set<String>set =new HashSet<String>();
        for(int i=0; i<num.length(); i++) set.add(num.charAt(i)+"");
        boolean ok;
        for(int d=1; d<=limit; ++d){
            if(x%d==0){
                div = x/d;
                n1 = d+"";
                n2 = div+"";
                ok = false;
                for(String digit :  set)
                    if(n1.contains(digit)){
                        ok = true;
                        break;
                    }
                if(ok) ans++;
                if(d == div) continue;
                ok = false;
                for(String digit :  set)
                    if(n2.contains(digit)){
                        ok = true;
                        break;
                    }
                if(ok) ans++;
            }
        }
        out.print(ans);
    }   
    
    static void out(Object ...o){ out.println(deepToString(o)); }    
    
    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }
        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        int nextInt(){ return parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
    }
}