#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
vector<int> ss[100005];
vector<int> tt[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i < (n); i++) scanf("%d", &s[i]);
  ;
  for (int i = 0; i < (m); i++) scanf("%d", &t[i]);
  ;
  int dp[n + 1][m + 1];
  dp[0][0] = 1;
  for (auto i = 0; i < (n); i++) {
    dp[i][0] = 1;
    ss[s[i]].push_back(i);
  }
  for (auto i = 0; i < (m); i++) {
    dp[0][i] = 1;
    tt[t[i]].push_back(i);
  }
  dp[n][0] = 1;
  dp[0][n] = 1;
  for (int i = 1; i <= n; i++) {
    int si = s[i - 1];
    for (int j = 1; j <= m; j++) {
      int tj = t[j - 1];
      dp[i][j] = dp[i][j - 1];
      for (int k : ss[tj]) {
        if (k >= i) break;
        dp[i][j] = (dp[i][j] + dp[k][j - 1]) % MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
}
