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