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