#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string ret = "{";
  for (long long i = 0; i < static_cast<long long>(v.size()); i++) {
    if (!first) {
      ret += ", ";
    }
    first = false;
    ret += to_string(v[i]);
  }
  ret += "}";
  return ret;
}
template <size_t N>
string to_string(bitset<N> v) {
  string ret = "";
  for (size_t i = 0; i < N; i++) {
    ret += static_cast<char>('0' + v[i]);
  }
  return ret;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string ret = "{";
  for (const auto &x : v) {
    string s = to_string(x);
    if (!first) {
      ret += ", ";
    }
    if (s[0] == '{') {
      s = "\n" + s;
    }
    first = false;
    ret += s;
  }
  if (ret[ret.size() - 1] == '}') {
    ret += "\n}";
  } else {
    ret += "}";
  }
  return ret;
}
template <typename A, typename... Lest>
string to_string(A *v, long long n, Lest... L) {
  bool first = true;
  string ret = "{";
  for (long long i = 0; i < n; i++) {
    auto x = v[i];
    string s = to_string(x, L...);
    if (!first) {
      ret += ", ";
    }
    if (s[0] == '{') {
      s = "\n" + s;
    }
    first = false;
    ret += s;
  }
  if (ret[ret.size() - 1] == '}') {
    ret += "\n}";
  } else {
    ret += "}";
  }
  return ret;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void name_disp(string s) {
  cerr << "-------" << endl;
  cerr << s << ": " << endl;
}
void val_disp() { cerr << endl; }
template <typename First, typename... Lest>
void val_disp(First F, Lest... L) {
  cerr << to_string(F) << endl;
  val_disp(L...);
}
template <typename A, typename... Lest>
void val_disp(A *v, Lest... L) {
  cerr << to_string(v, L...) << endl;
  val_disp();
}
const long long INF = 1002003004005006007ll;
const long long M = 1000000007;
const long long dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const long long dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                               {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
long long dp[2020][2020];
long long sum[2020][2020];
long long n, m, s[2020], t[2020];
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &s[i]);
  for (long long j = 1; j <= m; j++) scanf("%lld", &t[j]);
  for (long long i = 0; i < n + 1; i++)
    for (long long j = 0; j < m + 1; j++) {
      dp[i][j] = 0;
      sum[i][j] = 0;
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = (sum[i - 1][j - 1] + 1) % M;
      } else {
        dp[i][j] = 0;
      }
      sum[i][j] =
          (sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + dp[i][j]) % M;
    }
  long long ret = (sum[n][m] + 1) % M;
  printf("%lld\n", ret);
  return 0;
};
