#include <bits/stdc++.h>
using namespace std;
void IO() {
  srand(chrono::steady_clock::now().time_since_epoch().count());
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int n, m;
long long int mod = 1e9 + 7;
int main() {
  IO();
  cin >> n >> m;
  vector<long long int> arr(n);
  vector<long long int> brr(m);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    cin >> arr[i];
  }
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m))) {
    cin >> brr[i];
  }
  vector<vector<long long int> > dp(n + 1, vector<long long int>(m + 1, 0));
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    for (__typeof(m + 1) j = (1) - ((1) > (m + 1));
         j != (m + 1) - ((1) > (m + 1)); j += 1 - 2 * ((1) > (m + 1))) {
      if (arr[i - 1] == brr[j - 1]) {
        dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j]) % mod;
      } else {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % mod;
      }
    }
  }
  cout << (dp[n][m] + 1) % mod;
  return 0;
}
