#include <bits/stdc++.h>
using namespace std;
int M = 1000000007;
int a[2003], b[2003];
int s[2002][2002];
int main() {
  int m, n;
  cin >> m >> n;
  for (int i = 1; i <= m; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  s[0][0] = 1;
  for (int i = 1; i <= m; i++) s[i][0] = 1;
  for (int j = 1; j <= n; j++) s[0][j] = 1;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) {
      long long ans;
      ans = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
      if (a[i] == b[j]) ans += s[i - 1][j - 1];
      ans %= M;
      s[i][j] = ans;
    }
  cout << s[m][n];
}
