#include <bits/stdc++.h>
std::istream& operator>>(std::istream& input, __int128_t& value) {
  long long tmp;
  input >> tmp;
  value = tmp;
  return input;
}
std::ostream& operator<<(std::ostream& output, const __int128_t value) {
  output << (long long)value;
  return output;
}
const int MAX_N = 1010;
const int MOD = 1e9 + 7;
__int128_t N, M;
__int128_t S[MAX_N], T[MAX_N];
__int128_t dp[MAX_N][MAX_N][2][2] = {};
__int128_t calc(int n, int m, int f1, int f2) {
  if (dp[n][m][f1][f2] != -1) {
    return dp[n][m][f1][f2];
  }
  __int128_t ret = 0;
  if (n == 0) {
    if (f1 == 1 && f2 == 0) {
      ret = 1;
    } else {
      ret = 0;
    }
  } else if (m == 0) {
    if (f1 == 0 && f2 == 1) {
      ret = 1;
    } else {
      ret = 0;
    }
  } else if (f1 == 1 && f2 == 1) {
    if (S[n] == T[m]) {
      ret += calc(n - 1, m - 1, 0, 0);
      ret += calc(n - 1, m - 1, 1, 0);
      ret += calc(n - 1, m - 1, 0, 1);
      ret += calc(n - 1, m - 1, 1, 1);
      ret %= MOD;
    } else {
      ret = 0;
    }
  } else if (f1 == 0 && f2 == 0) {
    ret += calc(n - 1, m - 1, 0, 0);
    ret += calc(n - 1, m - 1, 1, 0);
    ret += calc(n - 1, m - 1, 0, 1);
    ret += calc(n - 1, m - 1, 1, 1);
    ret %= MOD;
  } else if (f1 == 1) {
    assert(f2 == 0);
    ret += calc(n, m - 1, f1, 0);
    ret += calc(n, m - 1, f1, 1);
    ret %= MOD;
  } else {
    assert(f2 == 1);
    ret += calc(n - 1, m, 0, f2);
    ret += calc(n - 1, m, 1, f2);
    ret %= MOD;
  }
  dp[n][m][f1][f2] = ret;
  return ret;
}
int main(int argc, char** argv) {
  std::cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    std::cin >> S[i];
  }
  for (int i = 1; i <= M; i++) {
    std::cin >> T[i];
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      dp[i][j][0][0] = -1;
      dp[i][j][0][1] = -1;
      dp[i][j][1][0] = -1;
      dp[i][j][1][1] = -1;
    }
  }
  dp[0][0][1][1] = 1;
  dp[0][0][0][0] = 0;
  dp[0][0][0][1] = 0;
  dp[0][0][1][0] = 0;
  __int128_t ret = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      ret = (ret + calc(i, j, 1, 1)) % MOD;
    }
  }
  std::cout << ret << std::endl;
  return 0;
}
