#include <bits/stdc++.h>
using namespace std;
using VP = vector<pair<long long, long long> >;
using VVP = vector<VP>;
using VI = vector<long long>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
int main() {
  long long i, j;
  long long n, m;
  cin >> n >> m;
  long long s[2020], t[2020];
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= m; i++) cin >> t[i];
  VVI dp(2020, VI(2020, 0));
  for (i = 0; i < 2020; i++) {
    dp[i][0] = 1;
    dp[0][i] = 1;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (s[i] == t[j])
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
