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.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
        final int x = in.nextInt();
        int[] divisors = NumberUtils.getDivisors(x);
        int answer = Lambda.count(divisors, new Property<Integer>() {
            public boolean can(Integer item) {
                return haveCommonDigits(item, x);
            }
        });
        out.println(answer);
    }

    private boolean haveCommonDigits(int divisor, int x) {
        final String a = String.valueOf(divisor);
        final String b = String.valueOf(x);
        return Lambda.anyOf(new XRange('0', '0' + 10), new Property<Integer>() {
            public boolean can(Integer item) {
                return a.indexOf(item) >= 0 && b.indexOf(item) >= 0;
            }
        });
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void println(int x) {
        writer.println(x);
    }

    public void close() {
        writer.close();
    }

    }

class NumberUtils {
    public static int upDiv(int a, int b) {
        return a % b == 0 ? (a / b) : (a / b + 1);
    }

    public static int[] getDivisors(int x) {
        if (x < 0) {
            throw new IllegalArgumentException();
        }
        SimpleIntArrayBuilder result = new SimpleIntArrayBuilder();
        for (int i = 1; i * i <= x; i++) {
            if (x % i == 0) {
                result.append(i);
                if (i * i < x) {
                    result.append(x / i);
                }
            }
        }
        int[] toReturn = result.toIntArray();
        Arrays.sort(toReturn);
        return toReturn;
    }

    }

class Lambda {
    public static int count(int[] array, Property<Integer> property) {
        int result = 0;
        for (int i : array) {
            if (property.can(i)) {
                result++;
            }
        }
        return result;
    }

    public static <T> boolean anyOf(Iterable<? extends T> collection, Property<? super T> property) {
        for (T l : collection) {
            if (property.can(l)) {
                return true;
            }
        }
        return false;
    }

    }

interface Property<T> {
    boolean can(T item);
}

class XRange implements Iterable<Integer> {
    private final int from;
    private final int to;
    private final int step;
    private final boolean reversed;

    public XRange(int from, int to, int step, boolean reversed) {
        if (from > to || step <= 0) {
            throw new IllegalArgumentException();
        }
        this.from = from;
        this.to = to;
        this.step = step;
        this.reversed = reversed;
    }

    public XRange(int from, int to, int step) {
        this(from, to, step, false);
    }

    public XRange(int from, int to) {
        this(from, to, 1);
    }

    public XRange(int to) {
        this(0, to);
    }


    public Iterator<Integer> iterator() {
        if (!reversed) {
            return new Iterator<Integer>() {
                int cur = from;

                public boolean hasNext() {
                    return cur < to;
                }

                public Integer next() {
                    if (!hasNext())
                        throw new NoSuchElementException();
                    int result = cur;
                    cur += step;
                    return result;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        } else {
            int kUpper = NumberUtils.upDiv(to - from, step);
            final int firstNumber = from + (kUpper - 1) * step;
            return new Iterator<Integer>() {
                int cur = firstNumber;

                public boolean hasNext() {
                    return cur >= from;
                }

                public Integer next() {
                    if (!hasNext())
                        throw new NoSuchElementException();
                    int result = cur;
                    cur -= step;
                    return result;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    }
}

class SimpleIntArrayBuilder {
    int[] data;
    int length;
    int capacity;

    public SimpleIntArrayBuilder() {
        this(16);
    }

    public SimpleIntArrayBuilder(int initialCapacity) {
        this.capacity = initialCapacity;
        length = 0;
        data = new int[initialCapacity];
    }

    private void ensureCapacity(int neededCapacity) {
        while (neededCapacity > capacity) {
            capacity = (capacity << 1) + 1;
        }
        if (data.length < capacity) {
            data = Arrays.copyOf(data, capacity);
        }
    }

    public SimpleIntArrayBuilder append(int item) {
        ensureCapacity(length + 1);
        data[length++] = item;
        return this;
    }

    public int[] toIntArray() {
        return Arrays.copyOf(data, length);
    }


}

