#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long s[2010];
long long t[2010];
template <class type>
class SegmentTree {
 public:
  long long size;
  vector<type> tree;
  type def;
  type (*marge)(type, type);
  SegmentTree(long long n, type d, type (*m)(type, type)) {
    size = 1;
    def = d;
    marge = m;
    n++;
    while (size < n) {
      size *= 2;
    }
    tree.resize(2 * size);
    for (long long i = 0; i < size; i++) {
      tree[size - 1 + i] = def;
    }
    for (long long i = size - 2; i >= 0; i--) {
      tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }
    return;
  }
  SegmentTree(long long n, type array[], type d, type (*m)(type, type)) {
    size = 1;
    def = d;
    marge = m;
    n++;
    while (size < n) {
      size *= 2;
    }
    tree.resize(2 * size);
    for (long long i = 0; i < size; i++) {
      if (i < n)
        tree[size - 1 + i] = array[i];
      else
        tree[size - 1 + i] = def;
    }
    for (long long i = size - 2; i >= 0; i--) {
      tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }
    return;
  }
  void update(long long i, type val) {
    i = size - 1 + i;
    tree[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }
    return;
  }
  void add(long long i, type val) {
    i = size - 1 + i;
    tree[i] = (tree[i] + val) % 1000000007;
    while (i > 0) {
      i = (i - 1) / 2;
      tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }
    return;
  }
  type get(long long a, long long b, long long k, long long l, long long r) {
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return tree[k];
    type vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
    type vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
    return marge(vl, vr);
  }
  type get(long long a, long long b) { return get(a, b, 0, 0, size); }
};
long long marge(long long i, long long j) { return (i + j) % 1000000007; }
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (long long j = 0; j < m; j++) {
    cin >> t[j];
  }
  long long ans = 0;
  SegmentTree<long long> seg(n, 0, marge);
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        long long tmp = 1 + seg.get(j + 1, n);
        seg.add(j, tmp);
        ans = (ans + tmp) % 1000000007;
      }
    }
  }
  cout << (ans + 1) % 1000000007 << endl;
  return 0;
}
