#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
void dump(const vector<T>& vec) {
  for (const T& value : vec) {
    cout << value << " ";
  }
  cout << endl;
}
void dump(const vector<vector<long long>> dp) {
  cout << "dump start" << endl;
  for (auto row : dp) {
    dump(row);
  }
  cout << "dump end" << endl;
}
template <class T>
void expand(vector<T>& vec, int size, T value) {
  while (vec.size() < size) {
    vec.push_back(value);
  }
}
template <class T>
void add_mod(T& target, T operand) {
  target = (target + operand) % MOD;
}
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  int ss[n];
  int ts[m];
  for (int i = 0; i < n; i++) {
    cin >> ss[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> ts[i];
  }
  vector<vector<long long>> dp;
  dp.assign(m, {});
  for (int i = 0; i < n; i++) {
    vector<long long> ks = {1};
    for (int j = 0; j < m; j++) {
      bool is_same = ss[i] == ts[j];
      vector<long long> before_values(dp[j]);
      int k_size = ks.size();
      if (is_same) {
        expand(dp[j], k_size + 1, 0ll);
      }
      for (int k = 0; k < k_size; k++) {
        if (is_same) {
          add_mod(dp[j][k + 1], ks[k]);
        }
      }
      int before_size = before_values.size();
      expand(ks, before_size, 0ll);
      for (int k = 0; k < before_size; k++) {
        add_mod(ks[k], before_values[k]);
      }
    }
  }
  long long result = 1;
  for (const vector<long long>& dp2 : dp) {
    int size2 = dp2.size();
    for (int k = 0; k < size2; k++) {
      add_mod(result, dp2[k]);
    }
  }
  cout << result << endl;
  return 0;
}
