#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const long long defvalue = 0;
long long combine(long long a, long long b) { return a + b; }
class SegTree {
 public:
  vector<long long> val;
  long long n;
  SegTree(long long size) {
    n = 1;
    while (n < size) n <<= 1;
    val = vector<long long>(2 * n, defvalue);
  }
  SegTree(const vector<long long> &in) {
    n = 1;
    while (n < in.size()) n <<= 1;
    val = vector<long long>(2 * n, defvalue);
    for (long long i = n - 1 + in.size() - 1; i >= 0; i--) {
      if (n - 1 <= i)
        val[i] = in[i - (n - 1)];
      else
        val[i] = combine(val[i * 2 + 1], val[i * 2 + 2]);
    }
  }
  void update(long long i, long long a) {
    i += n - 1;
    val[i] += a;
    while (i > 0) {
      i = (i - 1) / 2;
      val[i] = combine(val[i * 2 + 1], val[i * 2 + 2]);
    }
  }
  long long query(long long a, long long b, long long k = 0, long long l = 0,
                  long long r = -1) {
    if (r == -1) r = n;
    if (r <= a || b <= l) return defvalue;
    if (a <= l && r <= b)
      return val[k];
    else
      return combine(query(a, b, k * 2 + 1, l, (l + r) / 2),
                     query(a, b, k * 2 + 2, (l + r) / 2, r));
  }
  long long get(long long x) { return val[n - 1 + x]; }
  void tmp() {
    for (long long i = 0; i < (val.size()); i++) cout << " " << val[i];
    cout << endl;
  }
};
class SegTree_2d {
 public:
  vector<SegTree> val;
  long long n;
  SegTree_2d(long long h, long long w) {
    n = 1;
    while (n < h) n <<= 1;
    val = vector<SegTree>(2 * n, SegTree(w));
  }
  SegTree_2d(const vector<vector<long long> > &in) {
    n = 1;
    while (n < in.size()) n <<= 1;
    val = vector<SegTree>(2 * n, SegTree(in[0].size()));
    for (long long i = n - 1 + in.size() - 1; i >= 0; i--) {
      if (i - (n - 1) < 0)
        for (long long j = 0; j < (val[i].val.size()); j++)
          val[i].val[j] = combine(val[i * 2 + 1].val[j], val[i * 2 + 2].val[j]);
      else
        val[i] = SegTree(in[i - (n - 1)]);
    }
  }
  void update(long long x, long long y, long long a) {
    x += n - 1;
    val[x].update(y, a);
    while (x > 0) {
      x = (x - 1) / 2;
      val[x].update(y, a);
    }
  }
  long long query(long long x1, long long y1, long long x2, long long y2,
                  long long k = 0, long long l = 0, long long r = -1) {
    if (r == -1) r = n;
    if (r <= x1 || x2 <= l) return defvalue;
    if (x1 <= l && r <= x2)
      return val[k].query(y1, y2);
    else
      return combine(query(x1, y1, x2, y2, k * 2 + 1, l, (l + r) / 2),
                     query(x1, y1, x2, y2, k * 2 + 2, (l + r) / 2, r));
  }
  long long get(long long x, long long y) { return val[n - 1 + x].get(y); }
  void tmp() {
    for (long long i = 0; i < (val.size()); i++) val[i].tmp();
  }
};
signed main(void) {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < (n); i++) cin >> a[i];
  for (long long i = 0; i < (m); i++) cin >> b[i];
  SegTree_2d st(n, m);
  long long ans = 1;
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) {
      if (a[i] == b[j]) {
        long long t = 0;
        if (i && j) t = st.query(0, 0, i, j);
        st.update(i, j, t + 1);
        (ans += t + 1) %= 1000000007;
      }
    }
  cout << ans << endl;
}
