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