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.*;

public class Main {

   // static class Scanner {
   // StreamTokenizer in;
   // boolean forceMode = false;
   //
   // Scanner(InputStream is, String codePage, boolean forceMode) {
   // in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
   // if (!forceMode) {
   // in.resetSyntax();
   // in.wordChars(33, 255);
   // in.whitespaceChars(0, 32);
   // }
   // }
   //
   // Scanner(InputStream is, String codePage) {
   // in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
   // if (!forceMode) {
   // in.resetSyntax();
   // in.wordChars(33, 255);
   // in.whitespaceChars(0, 32);
   // }
   // }
   //
   // String next() {
   // try {
   // in.nextToken();
   // return in.sval;
   // } catch (Exception e) {
   // throw new Error();
   // }
   // }
   //
   // int nextInt() {
   // if (forceMode) {
   // try {
   // in.nextToken();
   // return (int) in.nval;
   // } catch (Exception e) {
   // throw new Error();
   // }
   // } else {
   // return Integer.parseInt(next());
   // }
   // }
   //
   // long nextLong() {
   // if (forceMode) {
   // throw new Error("No long at force mod!");
   // } else {
   // return Long.parseLong(next());
   // }
   //
   // }
   //
   // double nextDouble() {
   // if (forceMode) {
   // try {
   // in.nextToken();
   // return in.nval;
   // } catch (Exception e) {
   // throw new Error();
   // }
   // } else {
   // return Double.parseDouble(next());
   // }
   // }
   // }

   static class Assertion {
      static void checkRE(boolean e) {
         if (!e) {
            throw new Error();
         }
      }

      static void checkTL(boolean e) {
         if (!e) {
            int idx = 1;
            while (idx > 0) {
               idx++;
            }
         }
      }
   }

   Scanner in;
   PrintWriter out;

   void solve() {
      int x = in.nextInt();
      int cnt = 0;
      String xSt = "" + x;
      for (int div = 1; div * div <= x; div++) {
         if (x % div == 0) {
            if (isOk(xSt, div)) {
               cnt++;
            }
            if (div * div != x) {
               if (isOk(xSt, x / div)) {
                  cnt++;
               }
            }
         }
      }
      out.println(cnt);
   }

   boolean isOk(String st, int div) {
      while (div > 0) {
         int lastDigit = div % 10;
         if (st.indexOf("" + lastDigit) != -1) {
            return true;
         }
         div /= 10;
      }
      return false;
   }

   final static String fileName = "";

   void run() {
      // try {
      // in = new Scanner(new FileInputStream(fileName + ".in"), "ISO-8859-1");
      // out = new PrintWriter(fileName + ".out", "ISO-8859-1");
      // } catch (FileNotFoundException e) {
      // throw new Error(e);
      //
      // } catch (UnsupportedEncodingException e) {
      // throw new Error(e);
      // }
      in = new Scanner(System.in);
      out = new PrintWriter(System.out);
      try {
         solve();
      } catch (Exception e) {
         throw new Error(e);
      } finally {
         out.close();
      }
   }

   public static void main(String[] args) {
      new Main().run();
   }
}