#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;
}
const long long mod = 1000000007;
long long sum[2005][2005];
long long dp[2005][2005];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N + 1), t(M + 1);
  for (int i = 1; i <= N; i++) cin >> s[i];
  for (int i = 1; i <= M; i++) cin >> t[i];
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1] + 1;
        dp[i][j] %= mod;
        sum[i][j] =
            sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + dp[i][j];
        sum[i][j] %= mod;
      } else {
        dp[i][j] = 0;
        sum[i][j] =
            sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + dp[i][j];
        sum[i][j] %= mod;
      }
    }
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      ans += dp[i][j];
      ans %= mod;
    }
  cout << ans << endl;
}
