#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  const long long mod = 1e9 + 7;
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  for (long long i = 0, i_len = (n); i < i_len; i++) cin >> s[i];
  vector<long long> t(m);
  for (long long i = 0, i_len = (m); i < i_len; i++) cin >> t[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 0, i_len = (n); i < i_len; i++) dp[i][0] = 1;
  for (long long i = 0, i_len = (m); i < i_len; i++) dp[0][i] = 1;
  for (long long i = 0, i_len = (n); i < i_len; i++) {
    for (long long j = 0, j_len = (m); j < j_len; j++) {
      dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod;
      if (s[i] == t[j]) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
    }
  }
  cout << (dp[n][m] + 2) << endl;
  return 0;
}
