#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1 << 29;
const long long INFL = 1LL << 60;
const long long mod = 1000000007;
long long dp[2005][2005];
int main() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  dp[0][0] = 1;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i < int(n); i++) cin >> s[i];
  for (int i = 0; i < int(m); i++) cin >> t[i];
  for (int i = 0; i < int(2005); i++) {
    dp[i][0] = 1;
    dp[0][i] = 1;
  }
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(m); j++) {
      dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      if (s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
