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