#include <bits/stdc++.h>
using namespace std;
long long fp(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long x = fp(a, b >> 1);
  if (b & 1) {
    return (((x * x) % 1000000007LL) * a) % 1000000007LL;
  } else
    return (x * x) % 1000000007LL;
}
long long calc(long long x) { return fp(x, 1000000007LL - 2); }
long long n, m;
long long a[100004], b[100004], r, gers = 1, ans;
int main() {
  scanf("%I64d%I64d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%I64d", &b[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0 && b[i] == 0) {
      long long temp =
          (((gers * (m * (m - 1) / 2) % 1000000007LL) % 1000000007LL) *
           calc((m * m) % 1000000007LL)) %
          1000000007LL;
      ans = (ans + temp) % 1000000007LL;
      gers = (gers * calc(m)) % 1000000007LL;
    } else if (b[i] == 0) {
      long long temp =
          (((gers * (a[i] - 1)) % 1000000007LL) * calc(m)) % 1000000007LL;
      ans = (ans + temp) % 1000000007LL;
      gers = (gers * calc(m) % 1000000007LL);
    } else if (a[i] == 0) {
      long long temp =
          (((gers * (m - b[i])) % 1000000007LL) * calc(m)) % 1000000007LL;
      ans = (ans + temp) % 1000000007LL;
      gers = (gers * calc(m) % 1000000007LL);
    } else if (a[i] > b[i]) {
      ans = (ans + gers) % 1000000007LL;
      break;
    } else if (a[i] < b[i])
      break;
  }
  printf("%I64d\n", ans);
  return 0;
}
