#include <bits/stdc++.h>
using namespace std;
vector<int> v[111111];
int s[2222], t[2222], d[2222][2222];
int main() {
  int n, m, p = 1e9 + 7;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i], v[s[i]].push_back(i);
  for (int i = 0; i < m; i++) cin >> t[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      d[i][j + 1] = d[i][j];
      for (int x : v[t[j]]) {
        if (x >= i) break;
        (d[i][j + 1] += d[x][j] + 1) %= p;
      }
    }
  }
  cout << (d[n][m] + 1) % p << endl;
  return 0;
}
