#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long LINF = (long long)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void print(const vector<long long> &v) {
  for (auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (int i = 0; i < (n); ++i) cin >> s[i];
  for (int i = 0; i < (m); ++i) cin >> t[i];
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 0));
  vector<vector<long long> > sm(n + 1, vector<long long>(m + 1, 0));
  for (int i = (1); i < (n + 1); ++i)
    for (int j = (1); j < (m + 1); ++j) {
      if (s[i - 1] != t[j - 1])
        dp[i][j] = 0;
      else
        dp[i][j] = (sm[i - 1][j - 1] + 1) % MOD;
      sm[i][j] =
          (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  cout << (sm[n][m] + 1) % MOD << endl;
  return 0;
}
