#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5, mo = 1e9 + 7;
long long a[maxn], b[maxn];
long long n, k, K, i, j, ans, M, p, q, x;
int main() {
  scanf("%I64d%I64d", &n, &k);
  K = n / k;
  M = 9;
  ans = 1;
  for (i = 2; i <= k; i++) M = M * 10 + 9;
  for (i = 1; i <= K; i++) scanf("%I64d", &a[i]);
  for (i = 1; i <= K; i++) scanf("%I64d", &b[i]);
  for (i = 1; i <= K; i++) {
    p = q = b[i];
    for (j = 2; j <= k; j++) {
      p *= 10;
      q = q * 10 + 9;
    }
    x = max(p - 1, 0ll) / a[i] + M / a[i] - q / a[i];
    if (b[i] != 0) x++;
    ans = ans * x % mo;
  }
  ans = (ans + mo) % mo;
  printf("%I64d", ans);
  return 0;
}
