#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[2020];
int T[2020];
signed long long num[2020][2020];
signed long long sum[2020][2020];
signed long long mo = 1000000007;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> M;
  for (i = 0; i < (N); i++) cin >> S[i];
  for (i = 0; i < (M); i++) cin >> T[i];
  for (x = 0; x < (2020); x++) sum[x][0] = sum[0][x] = 1;
  signed long long ret = 1;
  for (x = 0; x < (N); x++)
    for (y = 0; y < (M); y++) {
      if (S[x] == T[y]) {
        num[x + 1][y + 1] =
            (sum[x][y + 1] + sum[x + 1][y] + mo - sum[x][y]) % mo;
        ret += num[x + 1][y + 1];
      }
      sum[x + 1][y + 1] =
          (sum[x][y + 1] + sum[x + 1][y] + mo - sum[x][y] + num[x + 1][y + 1]) %
          mo;
    }
  cout << ret % mo << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
