#include <bits/stdc++.h>
void max_self(long long& a, long long b) { a = a > b ? a : b; }
void min_self(long long& a, long long b) { a = a < b ? a : b; }
const long long MAX_N = 2005;
using namespace std;
long long n, m;
long long s[MAX_N];
long long t[MAX_N];
long long pref[MAX_N][MAX_N];
int main() {
  cin >> n >> m;
  pref[0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    cin >> s[i];
    pref[i][0] = 1;
  }
  for (long long j = 1; j <= m; j++) {
    cin >> t[j];
    pref[0][j] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i] == t[j])
        pref[i][j] = (pref[i - 1][j] + pref[i][j - 1]) % 1000000007;
      else
        pref[i][j] =
            (pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]) % 1000000007;
    }
  }
  cout << pref[n][m] << endl;
  return 0;
}
