#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long 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[3000][3000];
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i < n && j < m && s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % 1000000007;
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % 1000000007;
      dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j]) % 1000000007;
    }
  }
  long long int cnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cnt += dp[i][j];
  cout << dp[n][m];
}
