#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
unsigned int s[3001], t[3001], dp[3001][3001] = {0};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  unsigned int n, m;
  cin >> n >> m;
  for (unsigned int i = 0; i < unsigned int(n); i++) {
    cin >> s[i];
    dp[i][0] = 1;
  }
  dp[n][0] = 1;
  for (unsigned int i = 0; i < unsigned int(m); i++) {
    cin >> t[i];
    dp[0][i] = 1;
  }
  dp[0][m] = 1;
  for (unsigned int i = 0; i < unsigned int(n); i++)
    for (unsigned int j = 0; j < unsigned int(m); j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % 1000000007;
      } else {
        dp[i + 1][j + 1] =
            (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % 1000000007;
      }
    }
  cout << dp[n][m] << "\n";
}
