#include <bits/stdc++.h>
using namespace std;
int dp[2004][2004];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int(i) = 0; (i) < (n); (i)++) cin >> a[i];
  for (int(i) = 0; (i) < (m); (i)++) cin >> b[i];
  for (int(i) = 0; (i) < (n + 1); (i)++) dp[i][0] = 1;
  for (int(i) = 0; (i) < (m + 1); (i)++) dp[0][i] = 1;
  for (int(i) = 0; (i) < (n + 1); (i)++)
    for (int(j) = 0; (j) < (m + 1); (j)++) {
      if (i == 0 || j == 0) {
        continue;
      }
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      dp[i][j] = (dp[i][j] - dp[i - 1][j - 1]) % 1000000007;
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % 1000000007;
      }
    }
  cout << dp[n][m] << endl;
}
