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