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

public class Main {
    
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    
}

class Task {
    
    boolean fnd(int a, int b) {
        String aa = Integer.valueOf(a).toString(), 
                bb = Integer.valueOf(b).toString();
        for(char c = '0'; c <= '9'; ++c) {
            if(aa.indexOf(c) != -1 && bb.indexOf(c) != -1) {
                return true;
            }
        }
        return false;
    }
    
    public void solve(FastReader in, PrintWriter out) throws IOException {
 
        int n = in.nextInt(), ans = 0;
        for(int i = 1; i * i <= n; ++i) {
            if(n % i != 0) continue;
            ans += fnd(n, i) == true ? 1 : 0;
            if(n / i != i) {
                ans += fnd(n, n / i) == true ? 1 : 0;
            }
        }
        out.println(ans);
    }
    
}

class FastReader {
    
    BufferedReader in;
    StringBuilder sb = new StringBuilder();
    
    public FastReader(BufferedReader in) {
        this.in = in;
    }
    
    public String next() throws IOException {
        sb.setLength(0);
        while(true) {
            int c = in.read();
            if(c == -1) {
                return null;
            }
            if(" \n\r\t".indexOf(c) == -1) {
                sb.append((char)c);
                break;
            }
        }
        while(true) {
            int c = in.read();
            if(c == -1 || " \n\r\t".indexOf(c) != -1) {
                break;
            }
            sb.append((char)c);
        }
        return sb.toString();
    }
    
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    
}
