#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long pow_quick(long long a, long long b) {
  long long r = 1, base = a;
  while (b) {
    if (b & 1) {
      r *= base;
      r %= mod;
    }
    base *= base;
    base %= mod;
    b >>= 1;
  }
  return r;
}
long long a[100005];
long long b[100005];
int main() {
  long long n, m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long pm = pow_quick(m, mod - 2ll);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    ;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    ;
  }
  long long sum = 0ll;
  long long temp = 1ll;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0ll && b[i] == 0ll) {
      sum += (((((temp * pow_quick(m, mod - 2ll)) % mod) * (m - 1)) % mod) *
              pow_quick(2ll, mod - 2ll)) %
             mod;
      sum %= mod;
      temp *= pm;
      temp %= mod;
    } else if (a[i] == 0ll) {
      sum += (((temp * pm) % mod) * (m - b[i])) % mod;
      sum %= mod;
      temp *= pm;
      temp %= mod;
    } else if (b[i] == 0ll) {
      sum += (((temp * pm) % mod) * (a[i] - 1ll)) % mod;
      sum %= mod;
      temp *= pm;
      temp %= mod;
    } else if (a[i] > b[i]) {
      sum += temp;
      sum %= mod;
      temp *= pm;
      temp %= mod;
      break;
    } else if (a[i] < b[i]) {
      break;
    } else if (a[i] == b[i]) {
    }
  }
  printf("%lld", sum);
  printf("\n");
  return 0;
}
