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