#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n / m), b(n / m);
  int Len = 1;
  for (int i = 0; i < m; ++i) Len *= 10;
  for (int i = 0; i < n / m; ++i) scanf("%d", &a[i]);
  for (int j = 0; j < n / m; ++j) scanf("%d", &b[j]);
  vector<long long> mul(n / m, 0);
  long long ans = 1;
  for (int i = 0; i < n / m; ++i) {
    mul[i] = (int)ceil((double)Len / a[i]);
    int f = (double)ceil((b[i] * (Len / 10)) / (double)a[i]);
    f *= a[i];
    int y = (Len / 10) * (b[i] + 1);
    mul[i] -= (ceil((double)y / a[i]) - ceil((double)f / a[i]));
    if (!mul[i]) {
      puts("0");
      break;
    }
    ans *= mul[i];
    ans %= N;
  }
  printf("%lld\n", ans);
  return 0;
}
