import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static int ans = 0; static int k; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); k = sc.nextInt(); check(8, new boolean[9], 0); System.out.println(ans); } static void check(int idx, boolean[] used, int value) { if (idx == 0) { if (value % k == 0) { ans++; } return; } for (int i = 1; i <= 8; i++) { if (used[i]) { continue; } used[i] = true; check(idx - 1, used, value * 10 + i); used[i] = false; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }