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