#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n];
  int t[m];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  long long dp[n][m];
  long long sum[n + 1][m + 1];
  for (int i = 0; i < n + 1; i++) sum[i][0] = 0;
  for (int i = 0; i < m + 1; i++) sum[0][i] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j])
        dp[i][j] = (sum[i][j] + 1) % mod;
      else
        dp[i][j] = 0;
      sum[i + 1][j + 1] =
          (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i][j]) % mod;
    }
  }
  cout << (sum[n][m] + 1) % mod << endl;
}
