#include <bits/stdc++.h>
using namespace std;
static const long long md = 1e9 + 7;
static const long long mx = 100000;
int main(int, char**) {
  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) cin >> s[i];
  for (int i = 0; i < m; ++i) cin >> t[i];
  vector<long long> x1(n + 1, 0);
  vector<long long> x2(n + 1);
  x2[0] = 0;
  long long* y1;
  long long* y2;
  for (int i = 0; i < m; ++i) {
    if (i % 2 == 0) {
      y1 = &(x1[0]);
      y2 = &(x2[0]);
    } else {
      y1 = &(x2[0]);
      y2 = &(x1[0]);
    }
    for (int j = 0; j < n; ++j) {
      if (s[j] == t[i]) {
        y2[j + 1] = (y2[j] + y1[j + 1] + 1);
      } else {
        y2[j + 1] = (y2[j] + y1[j + 1] - y1[j]);
      }
      if (y2[j + 1] >= md) y2[j + 1] -= md;
    }
  }
  cout << (y2[n] + 1) << endl;
  return 0;
}
