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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.*;

//import java.text.DecimalFormat;
/**
 *
 * @author emaK
 */
public class Main {

    /* ArrayList<Integer> fun(int x) {
    int t=x;
    
    ArrayList<Integer> a = new ArrayList<Integer>();
    ArrayList<Integer> b = new ArrayList<Integer>();
    
    int i;
    i = 2;
    int p = 2;
    a.add(i);
    int u = 0;
    int j = i;
    // System.out.println("aaaaaaaaaaaaaaaaa");
    while (i <= t) {
    // System.out.println(j);
    if (i * i <= t) {
    
    j =i* p;
    if (j <= t) {
    if (!b.contains(j)) {
    b.add(j);
    }
    p++;
    continue;
    } else {
    // p = 2;
    if (!b.contains(i + 1)) {
    
    i++;
    j = i;
    a.add(j);
    p = 2;
    continue;
    
    } else {
    
    i++;
    if (i <= t) {
    //b.add(i);
    j = i;
    continue;
    }
    
    }
    }
    } else {
    if (!b.contains(i + 1)) {
    if (i + 1 <= t) {
    a.add(i + 1);
    }
    i++;
    j = i;
    p = 2;
    continue;
    } else {
    i++;
    }
    }
    
    }
    //  System.out.println("aaaaaaaaaaaaaaaaa");
    return a;
    }*/
    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {

        Scanner next;
        next = new Scanner(System.in);
        int x;
        x=next.nextInt();
        int y=(int)Math.sqrt((double)x);
        int r=0;
        if(x==1)
            r=0;
        String a="",b="";
        b+=x;
        for(int i=1;i<=y;i++)
        {
            if(x%i==0)
            {
                int h=x/i;
                if(h!=i)
                {a+=h;
                for(int j=0;j<a.length();j++)
                {
                    if(b.indexOf(a.charAt(j))!=-1)
                    {
                        r++;
                        a="";
                        break;
                    }
                }}
                a+=i;
                for(int j=0;j<a.length();j++)
                {
                    if(b.indexOf(a.charAt(j))!=-1)
                    {
                        r++;
                        a="";
                        break;
                    }
                }
            }
            
        }
        System.out.println(r);
        
        
        
        
        
        
        
        
        
        
        
        
        /*long x, y;
        x = next.nextInt();
        Main m = new Main();
        ArrayList<Long> ss = new ArrayList<Long>();
        ArrayList<Integer> sss = new ArrayList<Integer>();
        for (int i = 0; i < x; i++) {
        y = next.nextLong();
        ss.add(y);
        //System.out.println(m.fun(y));
        }
        long g = Collections.max(ss);
        int t;
        double yy = g;
        yy = Math.sqrt(yy);
        t = (int) yy;
        //System.out.println("jjjjjjj");
        sss = m.fun(t);
        // sss.remove(sss.size());
        //    System.out.println("aaaaaaaaaaaaaaaaa");
        double k;
        int j;
        /*for (int i = 0; i < sss.size(); i++) {
        System.out.println(sss.get(i));
        }
        for (int i = 0; i < x; i++) {
            
            k = ss.get(i);
            k = Math.sqrt(k);
            j = (int) k;
            if (k - j == 0) {
                if (sss.contains(j) == true) {
                    System.out.println("YES");
                    continue;
                }
                System.out.println("NO");
                
                continue;
                
            }
            System.out.println("NO");
            
        }*/
                
                
                

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        /*    String x;
         int y;
         y=next.nextInt();
         x=next.next();
         int n=0;
         n/=y;
         ArrayList <Integer>a=new ArrayList<Integer>();
         ArrayList <Integer>b=new ArrayList<Integer>();
         for(int i=0;i<n;i++)
         {
         int t=x.charAt(i);
         a.add(t);
         System.out.println(t);
         }
         for(int i=n;i<x.length();i++)
         {
         int t=x.charAt(i);
         b.add(t);
         System.out.println(t);
         }
      
         for(int i=0;i<n;i++)
         {
         System.out.println(a.get(i));
         }
         for(int i=0;i<n;i++)
         {
         System.out.println(b.get(i));
         }
         Collections.sort(a);
         Collections.sort(b);
         for(int i=0;i<n;i++)
         {
         System.out.println(a.get(i));
         }
         for(int i=0;i<n;i++)
         {
         System.out.println(b.get(i));
         }
         int r=0,q=0,e=0;
         for(int i=0;i<n;i++)
         {
         if(a.get(i)<b.get(i))
         {
         if(r==1)
         {e=1;
         break;
         }
         q=1;
         continue;
         }
         else
         {
         if(q==1)
         {e=1;
         break;
         }
         r=1;
         }
         }
         if(e==1)
         System.out.println("NO");
      
         else
         System.out.println("YES");*/
        /*
         String s,t;
         s=next.next();
         t=next.next();
         String j="";
         int h=0;
         for(int i=0;i<s.length();i++)
         {
         /*if(i<s.length()-1)
         {
         j+=(char)(s.charAt(i));
         }
         else
         {
         if((s.charAt(i)==t.charAt(i))||(t.charAt(i)-s.charAt(i)==1))
         {
         continue;
         }
         else
         {
         h=1;
         j+=(char)(s.charAt(i)+1);
         }
         }*/
      //System.out.println(i);
    /*  if((s.charAt(i)==t.charAt(i))||(t.charAt(i)-s.charAt(i)==1))
         {
         //j+=t.charAt(i);
         //System.out.println(i);
         continue;
         }
         else
         {
         // if(i<s.length()-1)
         // System.out.println(i);
         //{
         //h=1;
         j+=(char)(s.charAt(i)+1);
         // }else
          
          
         }
         }
    
         // System.out.println("Noggggggggggggggg");
         if(h==0)
         System.out.println("No such string");
         else
         {
         for()
            
         System.out.println(j);
         }*/
    }
}

/*  for(float i=0;i<=2.1;i+=.2)
 {
 for(float j=1+i;j<=3+i;j++)
 {
 Scanner next;
 next = new Scanner(System.in);
 DecimalFormat df = new DecimalFormat("#.0");
 float x=j+i;
 System.out.println("I="+df.format(i)+" "+"J="+df.format(j));
        
 }
 }
        
 */
        // TODO code application logic here
