#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, N = 100005;
long long n, m, ny_m, ny_2;
long long s1[N], s2[N];
long long ny(long long x) {
  long long sum = 1;
  for (long long a = mod - 2; a; a >>= 1, x = x * x % mod)
    if (a & 1) sum = sum * x % mod;
  return sum;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%I64d", s1 + i);
  for (int i = 1; i <= n; ++i) scanf("%I64d", s2 + i);
  long long ans = 0, now = 1;
  ny_m = ny(m);
  ny_2 = ny(2);
  for (int i = 1; i <= n; ++i) {
    if (s1[i] && s2[i]) {
      if (s1[i] > s2[i]) ans = (ans + now) % mod;
      if (s1[i] != s2[i]) {
        printf("%I64d", ans);
        return 0;
      }
    } else {
      if (s1[i]) {
        ans = (now * (s1[i] - 1) % mod * ny_m % mod + ans) % mod;
        now = now * ny_m % mod;
      } else if (s2[i]) {
        ans = (now * (m - s2[i]) % mod * ny_m % mod + ans) % mod;
        now = now * ny_m % mod;
      } else {
        ans = (now * (1LL + mod - ny_m) % mod * ny_2 % mod + ans) % mod;
        now = now * ny_m % mod;
      }
    }
  }
  printf("%I64d", ans);
  return 0;
}
