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