#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const long long MOD = (long long)1000000007;
const long long INF2 = (long long)100000000000000000;
long long dp[2010][2010];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1);
  for (int i = 1; i < n + 1; i++) {
    cin >> s[i];
  }
  vector<int> t(m + 1);
  for (int i = 1; i < m + 1; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n + 1; i++) {
    dp[i][0] = 1;
  }
  for (int i = 0; i < m + 1; i++) {
    dp[0][i] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = dp[i - 1][j - 1] * 2;
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD;
        dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
