#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  ;
  int n, m;
  cin >> n >> m;
  vector<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];
  }
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 0));
  for (int i = 0; i <= n; ++i) {
    dp[i][0] = 1;
  }
  for (int j = 0; j <= m; ++j) {
    dp[0][j] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] += dp[i - 1][j];
      dp[i][j] += dp[i][j - 1];
      dp[i][j] %= mod;
      if (s[i - 1] != t[j - 1]) {
        dp[i][j] -= dp[i - 1][j - 1];
      }
    }
  }
  cout << (dp[n][m] < 0 ? (dp[n][m] + mod) % mod : dp[n][m] % mod) << '\n';
  return 0;
}
