#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long int MAX_N = 1 << 17;
using namespace std;
long long int dy[] = {0, 0, 1, -1, 0};
long long int dx[] = {1, -1, 0, 0, 0};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
long long int n, m, s[2001], t[2001], sumarray[2001] = {0};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> t[i];
  }
  long long int out = 1;
  for (long long int i = 0; i < m; i++) {
    long long int temp = 0;
    for (long long int j = 0; j < n; j++) {
      if (j) {
        if (t[i] == s[j]) {
          sumarray[j] += (temp + 1) % 1000000007;
          temp = temp + sumarray[j];
        } else {
          temp += sumarray[j];
        }
      } else {
        temp += sumarray[j];
        if (t[i] == s[j]) {
          sumarray[j] += 1;
        }
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    out += sumarray[i];
    out %= 1000000007;
  }
  cout << out << endl;
  return 0;
}
