#include <bits/stdc++.h>
using namespace std;
long long n;
long long ncr(long long n, long long r) {
  long long i, ans = 1, k = 0;
  if (r == 0)
    return 1;
  else if (n < r)
    return 0;
  for (i = n; i >= n - r + 1; i--) {
    ans *= i;
    ans /= n - i + 1;
  }
  return ans;
}
void max_heapify(int a[100], int i) {
  int l, r, largest = i;
  l = 2 * i + 1;
  r = 2 * i + 2;
  if (l < n && a[l] > a[i]) largest = l;
  if (r < n && a[r] > a[l]) largest = r;
  if (largest != i) {
    int k;
    k = a[i];
    a[i] = a[largest];
    a[largest] = k;
    max_heapify(a, largest);
  }
}
int power(long long x, long long y, long long p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool square(long long n) {
  double x;
  x = sqrt(n);
  if (x == floor(x))
    return true;
  else
    return false;
}
bool prime(long long n) {
  long long i;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long modi(long long a, long long m) { return power(a, m - 2, m); }
void kmp(string s, long long p[]) {
  int n = (int)s.length();
  p[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = p[i - 1];
    while (j > 0 && s[i] != s[j]) j = p[j - 1];
    if (s[i] == s[j]) j++;
    p[i] = j;
  }
}
void zfunc(string s, long long z[]) {
  long long n = (long long)s.length();
  z[0] = 0;
  for (long long i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
}
struct pair_hash {
  size_t operator()(const pair<int, int>& p) const noexcept {
    return hash<long long>()((((long long)p.first) << 32) |
                             ((long long)p.second));
  }
};
bool palin(string s) {
  long long i, n;
  n = s.length();
  for (i = 0; i <= n / 2; i++) {
    if (s[i] != s[n - i - 1]) {
      return false;
    }
  }
  return true;
}
long long sum(long long n) {
  long long i;
  i = n;
  long long sum = 0;
  while (i > 0) {
    sum += i % 10;
    i = i / 10;
  }
  return sum;
}
long long nCr(long long n, long long r, long long p, long long fac[]) {
  if (r == 0) return 1;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modi(fac[r], p) % p * modi(fac[n - r], p) % p) % p;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long mod(string num, long long a) {
  long long res = 0;
  for (long long i = 0; i < num.length(); i++)
    res = (res * 10 + (long long)num[i] - '0') % a;
  return res;
}
long long parent[1000], sizer[1000];
long long findset(long long a) {
  if (a == parent[a]) {
    return a;
  }
  parent[a] = findset(parent[a]);
  return parent[a];
}
void unionset(long long a, long long b) {
  a = findset(a);
  b = findset(b);
  if (sizer[a] < sizer[b]) {
    swap(a, b);
  }
  sizer[b] += sizer[a];
  parent[b] = a;
}
struct fenwick {
  vector<long long> bit;
  long long n;
  fenwick(long long n, vector<long long> v) {
    this->n = n;
    bit.assign(n, 0);
    for (long long it = 0; it < n; it++) {
      add(it, v[it]);
    }
  }
  long long sum(long long idx) {
    if (idx < 0) return 0;
    long long ret = 0;
    for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {
      ret += bit[idx];
    }
    return ret;
  }
  void add(long long idx, long long x) {
    for (; idx < n; idx = idx | (idx + 1)) {
      bit[idx] += x;
      bit[idx] = max(0LL, bit[idx]);
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long T = 1, i, j;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> s(n), t(m);
    for (i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (i = 0; i < m; i++) {
      cin >> t[i];
    }
    long long dp[100][100] = {0};
    long long dp2[100][100] = {0};
    long long ans = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (s[i] != t[j]) {
          continue;
        }
        dp[i + 1][j + 1] = (dp2[i][j] + 1) % 1000000007;
        dp2[i + 1][j + 1] =
            (dp2[i][j + 1] + dp2[i + 1][j] - dp2[i][j] + dp[i + 1][j + 1]) %
            1000000007;
        ans += dp[i + 1][j + 1];
        ans %= 1000000007;
      }
    }
    cout << (ans + 1) % 1000000007;
  }
  return 0;
}
