import java.util.LinkedHashSet; import java.util.Scanner; public class Main { static int k, ans; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); k = sc.nextInt(); sc.close(); permutation(0, new LinkedHashSet<>()); System.out.println(ans); } static void permutation(int x, LinkedHashSet set) { if (x > 10000000) { if (x % k == 0) { ans++; } return; } for (int i = 1; i <= 8; i++) { if (!set.contains(i)) { set.add(i); permutation(x * 10 + i, set); set.remove(i); } } } }