#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, i, j;
  cin >> n >> m;
  vector<int> a(n), b(m);
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1)),
      sum(n + 1, vector<long long>(m + 1, 0));
  for (i = 0; i < (n); i++) cin >> a[i];
  for (i = 0; i < (m); i++) cin >> b[i];
  for (i = 0; i < (n); i++) {
    for (j = 0; j < (m); j++) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      if (a[i] == b[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + 1] %= 1000000007;
    }
  }
  cout << dp[n][m] << "\n";
  return 0;
}
