#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238463;
const int N = 1e5 + 10;
const long long INF = 1LL << 60;
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
long long second[2010], t[2010];
long long ans[2010][2010];
int main() {
  int n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> second[i];
  for (long long i = 1; i <= m; i++) cin >> t[i];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      ans[i][j] = (ans[i - 1][j] + ans[i][j - 1]);
      if (second[i] != t[j]) ans[i][j] -= ans[i - 1][j - 1];
      if (second[i] == t[j]) ans[i][j]++;
      ans[i][j] %= 1000000007;
    }
  }
  cout << ans[n][m] + 1 << endl;
}
