#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = long long(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr long long LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
long long n, m, s[2005], t[2005], dp[2005][2005];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  dp[0][0] = 1;
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      dp[i][j] %= MOD;
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] += dp[i][j];
      }
      dp[i + 1][j] += dp[i][j];
      dp[i][j + 1] += dp[i][j];
      dp[i + 1][j + 1] -= dp[i][j];
    }
  }
  cout << dp[n][m] % MOD << endl;
  return 0;
}
