#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main(void) {
  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 j = 1; j <= m; j++) {
    cin >> t[j];
  }
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  vector<vector<int>> sum(n + 1, vector<int>(m + 1, 0));
  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]) % mod - sum[i - 1][j - 1];
      if (s[i] != t[j]) continue;
      dp[i][j] += sum[i - 1][j - 1] + 1;
      dp[i][j] %= mod;
      sum[i][j] += dp[i][j];
      sum[i][j] %= mod;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans += dp[i][j];
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}
