#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n + 1), t(m + 1);
  for (long long i = 1; i <= n; ++i) cin >> s[i];
  for (long long i = 1; i <= m; ++i) cin >> t[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1));
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (s[i] == t[j]) {
        dp[i][j] += dp[i - 1][j - 1];
      }
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
