#include <bits/stdc++.h>
const int MXN = 1e6 + 200;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;
using namespace std;
int n, m;
long long a[MNN], b[MNN], dp[MNN][MNN];
int main() {
  ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int j = 1; j <= m; j++) {
    cin >> b[j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
      if (a[i] == b[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MOD;
      }
    }
  }
  cout << (dp[n][m] + 1) % MOD;
  return 0;
}
