#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int *v1, *v2;
  int n, m;
  long long int ans = 0;
  cin >> n >> m;
  int tmp;
  v1 = new int[n];
  v2 = new int[m];
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v1[i] = tmp;
  }
  for (int i = 0; i < m; i++) {
    cin >> tmp;
    v2[i] = tmp;
  }
  long long int **dp = new long long int *[n];
  for (int i = 0; i < n; i++) {
    dp[i] = new long long int[m];
  }
  long long int **dps = new long long int *[n + 1];
  for (int i = 0; i <= n; i++) {
    dps[i] = new long long int[m + 1];
  }
  for (int i = 0; i <= n; i++) {
    dps[i][0] = 0;
  }
  for (int i = 0; i <= m; i++) {
    dps[0][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = 0;
      if (v1[i] == v2[j]) {
        dp[i][j] = dps[i][j];
        dp[i][j]++;
        dp[i][j] %= 1000000007;
      }
      dps[i + 1][j + 1] = dps[i + 1][j] % 1000000007 +
                          dps[i][j + 1] % 1000000007 - dps[i][j] % 1000000007 +
                          dp[i][j] % 1000000007;
      dps[i + 1][j + 1] %= 1000000007;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans += dp[i][j];
      ans %= 1000000007;
    }
  }
  ans++;
  cout << ans;
}
