#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
vector<vector<int> > mul(vector<vector<int> > &A, vector<vector<int> > &B) {
  vector<vector<int> > C(A.size(), vector<int>(B[0].size()));
  for (int i = 0; i < A.size(); i++) {
    for (int k = 0; k < B.size(); k++) {
      for (int j = 0; j < B[0].size(); j++) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
      }
    }
  }
  return C;
}
vector<vector<int> > pow(vector<vector<int> > A, long long n) {
  vector<vector<int> > B(A.size(), vector<int>(A.size()));
  for (int i = 0; i < A.size(); i++) {
    B[i][i] = 1;
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
int main() {
  long long n, m;
  cin >> n >> m;
  long long s[n], t[m];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  long long dp[n + 1][m + 1];
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) dp[i + 1][0] = 1;
  for (int i = 0; i < m; i++) dp[0][i + 1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      }
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
