#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  V s(n), t(m);
  for (int i = int(0); i < int(n); i++) cin >> s[i];
  for (int i = int(0); i < int(m); i++) cin >> t[i];
  VVll dp(n + 1, Vll(m + 1));
  for (int i = int(0); i < int(n + 1); i++) dp[i][0] = 1;
  for (int i = int(0); i < int(m + 1); i++) dp[0][i] = 1;
  for (int i = int(0); i < int(n); i++)
    for (int j = int(0); j < int(m); j++) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
      if (s[i] != t[j]) dp[i + 1][j + 1] -= dp[i][j];
      dp[i + 1][j + 1] %= MOD;
    }
  cout << dp[n][m] << endl;
  return 0;
}
