#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n;
  cin >> n;
  ;
  long long m;
  cin >> m;
  ;
  ;
  vector<long long> hoge(n);
  for (long long i = 0; i < n; i++) {
    cin >> hoge[i];
  }
  vector<long long> huga(m);
  for (long long i = 0; i < m; i++) {
    cin >> huga[i];
  }
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 0; i < n + 1; i++) {
    dp[i][0] = 1;
  }
  for (long long j = 0; j < m + 1; j++) {
    dp[0][j] = 1;
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
      if (hoge[i - 1] == huga[j - 1]) {
        dp[i][j] = (dp[i - 1][j - 1] + dp[i][j]) % 1000000007;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
