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