#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e+18 + 1;
const long long MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector<long long> dx = {0, 0, 1, -1};
vector<long long> dy = {1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  vector<vector<long long> > sum(2010, vector<long long>(2010));
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> s[i];
  vector<long long> t(m);
  for (long long i = 0; i < (long long)(m); i++) cin >> t[i];
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(m); j++) {
      if (i != 0) sum[i][j] += sum[i - 1][j];
      sum[i][j] %= MOD;
      if (j != 0) sum[i][j] += sum[i][j - 1];
      sum[i][j] %= MOD;
      if (i != 0 && j != 0) sum[i][j] += MOD - sum[i - 1][j - 1];
      sum[i][j] %= MOD;
      if (s[i] == t[j] && i != 0 && j != 0) {
        sum[i][j] += sum[i - 1][j - 1];
        sum[i][j] %= MOD;
      }
      if (s[i] == t[j]) {
        sum[i][j]++;
        sum[i][j] %= MOD;
      }
    }
  }
  cout << sum[n - 1][m - 1] << endl;
}
