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