#include <bits/stdc++.h>
using namespace std;
int n, m, dp[2010][2010] = {}, pos, ans = 1;
vector<int> ver[100010], s, t;
int main() {
  int 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);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < i; j++) {
      for (k = 0; k < ver[s[i]].size(); k++) {
        for (l = 0; l < ver[s[j]].size(); l++) {
          if (ver[s[j]][l] >= ver[s[i]][k]) {
            break;
          }
          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;
      ans = (ans + dp[i][ver[s[i]][j]]) % 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
