#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1000000007;
int nm[2], st[2][2000];
long long rec1(long long, long long);
long long rec2(long long, long long);
long long dp[2][2000][2000][2];
long long rec1(long long a, long long b) {
  if (dp[0][a][b][0] == 0) {
    dp[0][a][b][0] = 1;
    dp[0][a][b][1] = (a < 0 || b < 0 || st[0][a] != st[1][b])
                         ? 0
                         : (rec2(a - 1, b - 1) + 1) % mod;
  }
  return dp[0][a][b][1];
}
long long rec2(long long a, long long b) {
  if (dp[1][a][b][0] == 0) {
    dp[1][a][b][0] = 1;
    dp[1][a][b][1] =
        (rec2(a - 1, b) + rec2(a, b - 1) - rec2(a - 1, b - 1) + rec1(a, b)) %
        mod;
  }
  return dp[1][a][b][1];
}
int main() {
  cin >> nm[0] >> nm[1];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < nm[i]; j++) {
      cin >> st[i][j];
    }
  }
  cout << (rec2(nm[0] - 1, nm[1] - 1) + 1) % mod << endl;
}
