#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int mod = 1e+9 + 7;
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  vector<vector<long long int>> dp(n + 1, vector<long long int>(m + 1, 0));
  vector<vector<long long int>> sum(n + 1, vector<long long int>(m + 1, 0));
  dp[0][0] = 1;
  long long int ans = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i - 1][j - 1];
      sum[i][j] %= mod;
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = sum[i][j];
      } else {
        dp[i][j] = 0;
      }
      ans += dp[i][j];
      ans %= mod;
    }
  }
  cout << ans << endl;
}
