#include <bits/stdc++.h>
using namespace std;
const int MX = (int)1e6 + 10;
const int mod = (int)1e9 + 7;
int main(int argc, char* argv[]) {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1), b(m + 1);
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  dp[0][0] = 1;
  for (int i = 0; i <= m; ++i) dp[0][i] = 1;
  for (int i = 0; i <= n; ++i) dp[i][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1];
      dp[i][j] += (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % mod;
      while (dp[i][j] >= mod) dp[i][j] -= mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
