#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int MOD = 1000000007;
int n, m, i, j;
int s[2005], t[2005], f[2005][2005];
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; ++i) cin >> s[i];
  for (i = 1; i <= m; ++i) cin >> t[i];
  for (i = 0; i <= n; ++i) f[i][0] = 1;
  for (i = 0; i <= m; ++i) f[0][i] = 1;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
      if (s[i] == t[j]) f[i][j] += f[i - 1][j - 1];
      f[i][j] %= MOD;
    }
  }
  cout << f[n][m] << endl;
  return 0;
}
