#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1e9 + 7;
const int inf = 1 << 30;
long long dp[2010][2010];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  vector<int> t(m);
  for (int i = 0; i < (int)(m); i++) cin >> t[i];
  dp[0][0] = 1;
  for (int i = 0; i < (int)(n + 1); i++) {
    for (int j = 0; j < (int)(m + 1); j++) {
      if (i < n && j < m && s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j] += dp[i][j];
      dp[i][j + 1] += dp[i][j];
      dp[i + 1][j + 1] -= dp[i][j];
      dp[i + 1][j + 1] %= mod;
      dp[i + 1][j] %= mod;
      dp[i][j + 1] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
