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.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) throws IOException {
		Task task = new Task();
		task.getData();
		task.solve();
		task.printAnswer();
	}
}

class Task {
	int n;

	//StringBuilder answer = new StringBuilder();
	int answer = 0;

	public void getData() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("input.txt"));

		n = Integer.parseInt(br.readLine());
		/*	
		for (int i = 0; i < rounds.length; ++i) {
			rounds[i] = br.readLine();
		}*/
		
		br.close();
	}

	public void solve() {
		for (int d = 1; d <= Math.sqrt(n + .0); ++d) {
			if (n % d != 0) {   //n / d && d
				continue;
			}
			Set<String> first = new HashSet<String>();
			first.addAll(Arrays.asList(Integer.toString(n).split("(?!^)")));
			
			Set<String> second = new HashSet<String>();
			second.addAll(Arrays.asList(Integer.toString(d).split("(?!^)")));
			
			Set<String> firstCopy = new HashSet<String>();
			firstCopy.addAll(first);
			firstCopy.removeAll(second);
			
			if (first.size() > firstCopy.size()) {
				++answer;
			}
			if (d * d == n) {
				continue;
			}
			
			second.clear();
			second.addAll(Arrays.asList(Integer.toString(n / d).split("(?!^)")));
			firstCopy.clear();
			firstCopy.addAll(first);
			firstCopy.removeAll(second);
			if (first.size() > firstCopy.size()) {
				++answer;
			}
		}
	}

	public void printAnswer() throws IOException {
		System.out.print(answer);
		// BufferedWriter bw = new BufferedWriter(new FileWriter(new
		// File("output.txt")));
		// bw.append(answer);
		// bw.close();
	}
}

class Library extends Object {
	public static ArrayList<Integer> firstPrimes(int bound) {
		boolean[] isPrime = new boolean[bound];
		Arrays.fill(isPrime, 2, isPrime.length, true);
		for (int i = 2; i <= Math.sqrt(bound); ++i) {
			if (isPrime[i]) {
				for (int j = i * i; j < bound; j += i) {
					isPrime[j] = false;
				}
			}
		}

		ArrayList<Integer> primes = new ArrayList<Integer>();
		for (int i = 0; i < isPrime.length; ++i) {
			if (isPrime[i]) {
				primes.add(i);
			}
		}
		return primes;
	}
}