#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> ss;
int m;
vector<int> ts;
vector<vector<int>> memo;
vector<vector<int>> memo2;
int d = 1e9 + 7;
int count_same(int s_idx, int t_idx) {
  if (s_idx >= n) {
    return 0;
  }
  if (t_idx >= m) {
    return 0;
  }
  if (memo[s_idx][t_idx] >= 0) {
    return memo[s_idx][t_idx];
  }
  int val = 0;
  val += count_same(s_idx, t_idx + 1);
  val += count_same(s_idx + 1, t_idx);
  val -= count_same(s_idx + 1, t_idx + 1);
  if (ss[s_idx] == ts[t_idx]) {
    val += 1 + count_same(s_idx + 1, t_idx + 1);
  }
  val = val % d;
  memo[s_idx][t_idx] = val;
  return val;
}
int main(void) {
  cin >> n;
  cin >> m;
  long long unsigned int s;
  for (int(i) = 0; (i) < (n); (i)++) {
    cin >> s;
    ss.push_back(s);
  }
  long long unsigned int t;
  for (int(i) = 0; (i) < (m); (i)++) {
    cin >> t;
    ts.push_back(t);
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    vector<int> v;
    for (int(j) = 0; (j) < (m); (j)++) {
      v.push_back(-1);
    }
    memo.push_back(v);
    memo2.push_back(v);
  }
  cout << count_same(0, 0) + 1 << endl;
  for (int(i) = 0; (i) < (n); (i)++) {
    cerr << "i"
         << " = " << (i) << endl;
    ;
    for (int(j) = 0; (j) < (m); (j)++) {
      cerr << "memo[i][j]"
           << " = " << (memo[i][j]) << endl;
      ;
    }
  }
  return 0;
}
