#include <bits/stdc++.h>
using namespace std;
int dp[2100][2100];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a[2100], b[2100];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1] + 1;
      }
      dp[i][j] += dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] %= int(1e9 + 7);
    }
  cout << (dp[n][m] + 1) % int(1e9 + 7) << endl;
}
