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