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.InputStreamReader;
import java.io.IOException;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author syu
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
        int x=in.nextInt();
        int k=x,x1=x;
        Set<Integer> ans=new HashSet<Integer>();
        if (x<10)
        {
            out.print(1);
            return;
        }
        Set<Integer> k1=new HashSet<Integer>();
        while (k>0)
        {
            k1.add(k%10);
            k/=10;
        }

        int i=1;
        while (i*i<=x)
        {
            if (x%i==0)
            {
                Set<Integer> temp=new HashSet<Integer>();
                int t1=i;
                int t=i;
                while (t>0)
                {
                    temp.add(t%10);
                    t/=10;

                }

                for (Integer q:temp)
                    if (k1.contains(q)) {
                        ans.add(t1);
                        //out.println(t1);
                        break;}
                if (i*i!=x1){

                t=x1/i;
                    t1=t;
                temp.clear();

                while (t>0)
                {
                    temp.add(t%10);
                    t/=10;

                }
                for (Integer q:temp)
                    if (k1.contains(q)) {
                        //out.println(t1);
                        ans.add(t1);        break;}
                }

            }
            i++;
        }
        out.print(ans.size());


	}
}

class InputReader {
    private BufferedReader br;
    private StringTokenizer st;

    public InputReader(InputStream stream) {
        br = new BufferedReader(new InputStreamReader(stream));
    }

    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String s = br.readLine();
                if (s == null) {
                    return null;
                }
                st = new StringTokenizer(s);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }

