#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> S, T;
vector<vector<long long>> dp, sum;
void input() {
  cin >> n >> m;
  S = vector<int>(n);
  T = vector<int>(m);
  for (int i = 0; i < (int)(n); i++) cin >> S[i];
  for (int i = 0; i < (int)(m); i++) cin >> T[i];
}
int main() {
  input();
  dp = sum = vector<vector<long long>>(n + 1, vector<long long>(m + 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] = (sum[i - 1][j - 1] + 1) % 1000000007;
      }
      sum[i][j] =
          (sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + dp[i][j]) %
          1000000007;
    }
  }
  long long ans = (sum[n][m] + 1) % 1000000007;
  cout << ans << endl;
}
