#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long keta(long long n) {
  string s = to_string(n);
  long long num = s.size();
  return num;
}
const long long INF = 1LL << 60;
const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<long long, int>;
class UnionFind {
 public:
  vector<int> Parent, diff_weight;
  UnionFind(int n) {
    Parent = vector<int>(n, -1);
    diff_weight = vector<int>(n, 0);
  }
  int root(int a) {
    if (Parent[a] < 0) return a;
    int r = root(Parent[a]);
    diff_weight[a] += diff_weight[Parent[a]];
    return Parent[a] = r;
  }
  int weight(int a) {
    root(a);
    return diff_weight[a];
  }
  bool issame(int a, int b) { return root(a) == root(b); }
  int size(int a) { return -Parent[root(a)]; }
  bool merge(int a, int b, int w = 0) {
    w += weight(a);
    w -= weight(b);
    a = root(a);
    b = root(b);
    if (a == b) return false;
    if (size(a) < size(b)) swap(a, b), w = -w;
    Parent[a] += Parent[b];
    Parent[b] = a;
    diff_weight[b] = w;
    return true;
  }
  int diff(int a, int b) { return weight(b) - weight(a); }
};
vector<int> MP(string s) {
  vector<int> A(s.size() + 1);
  A[0] = -1;
  int j = -1;
  for (int i = 0; i < s.size(); i++) {
    while (j >= 0 && s[i] != s[j]) j = A[j];
    j++;
    A[i + 1] = j;
  }
  return A;
}
vector<int> Manacher(string s) {
  vector<int> R(s.size());
  int i = 0, j = 0;
  while (i < s.size()) {
    while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) ++j;
    R[i] = j;
    int k = 1;
    while (i - k >= 0 && i + k < s.size() && k + R[i - k] < j)
      R[i + k] = R[i - k], k++;
    i += k;
    j -= k;
  }
  return R;
}
vector<int> Z_algorithm(string& s) {
  vector<int> Z(s.size());
  Z[0] = s.size();
  int i = 1, j = 0;
  while (i < s.size()) {
    while (i + j < s.size() && s[j] == s[i + j]) j++;
    Z[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    int k = 1;
    while (i + k < s.size() && k + Z[k] < j) Z[i + k] = Z[k], ++k;
    i += k;
    j -= k;
  }
  return Z;
}
const int MAX = 1e6 + 1;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % (1000000007);
    inv[i] = (1000000007) -
             inv[(1000000007) % i] * ((1000000007) / i) % (1000000007);
    finv[i] = finv[i - 1] * inv[i] % (1000000007);
  }
}
long long COM(long long n, long long k) {
  if (n >= MAX) {
    long long tmp = 1;
    for (int i = 0; i < k; i++) {
      tmp *= (n - i);
      tmp %= (1000000007);
    }
    return tmp * finv[k] % (1000000007);
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % (1000000007)) % (1000000007);
}
long long POW(long long x, long long n) {
  long long ret = 1;
  if (n < 0) {
    n *= -1;
    x = inv[x];
  }
  while (0 < n) {
    if (n % 2 == 0) {
      x = x * x % (1000000007);
      n /= 2;
    } else {
      ret = ret * x % (1000000007);
      n--;
    }
  }
  return ret;
}
int dp[2020][2020];
int sum[2020][2020];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  dp[0][0] = 1;
  sum[1][1] = 1;
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < m + 1; j++) {
      if (i - 1 >= 0 && j - 1 >= 0 && s[i - 1] == t[j - 1]) {
        dp[i][j] = sum[i][j];
      }
      sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i][j];
      dp[i][j] %= (1000000007);
      sum[i + 1][j + 1] %= (1000000007);
    }
  cout << sum[n + 1][m + 1] << endl;
}
