#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
signed 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>> num(n + 1, vector<long long>(m + 1, 0));
  vector<vector<long long>> sum(n + 1, vector<long long>(m + 1, 0));
  num[0][0] = 1;
  sum[0][0] = 1;
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) {
      if (i > 0 && j > 0 && s[i] == t[j]) {
        num[i][j] = sum[i][j];
      }
      sum[i + 1][j + 1] =
          (num[i][j] + sum[i + 1][j] + sum[i][j + 1] + mod - sum[i][j]) % mod;
    }
  cout << sum[n][m] << endl;
}
