#include <bits/stdc++.h>
using namespace std;
long long n, m, dp[2010][2010], pos, ans = 0;
vector<long long> ver[100010], tran[2010], s, t;
int main() {
  long long i, j, k, l, p;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> p;
    s.push_back(p);
  }
  for (i = 0; i < m; i++) {
    cin >> p;
    t.push_back(p);
    ver[p].push_back(i);
  }
  memset(dp, 0, sizeof(dp));
  for (i = 0; i < n; i++) {
    for (j = 0; j < i; j++) {
      for (k = 0; k < ver[s[i]].size(); k++) {
        pos = lower_bound(ver[s[j]].begin(), ver[s[j]].end(), ver[s[i]][k]) -
              ver[s[j]].begin();
        for (l = 0; l < pos; l++) {
          dp[i][ver[s[i]][k]] =
              (dp[i][ver[s[i]][k]] + dp[j][ver[s[j]][l]]) % 1000000007;
        }
      }
    }
    for (j = 0; j < ver[s[i]].size(); j++) {
      dp[i][ver[s[i]][j]] = (dp[i][ver[s[i]][j]] + 1) % 1000000007;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      ans = (ans + dp[i][j]) % 1000000007;
    }
  }
  cout << (ans + 1) % 1000000007 << endl;
  return 0;
}
