#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
//constexpr int INF = 1<<30;
//constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX = 2e3;
ll dp[N_MAX][N_MAX] = {{0}};
ll sum[N_MAX][N_MAX] = {{0}}; // 二次元累積和

int N, M;

void dump() {
  for (int j=0; j<M; j++) {
    cerr << "j " << j << ": ";
    for (int i=0; i<N; i++) {
      cerr << " " << sum[i][j];
    }
    cerr << endl;
  }
}

int main(int argc, char** argv) {
  cin >> N >> M;

  vi S(N);
  for (int i=0; i<N; i++) {
    cin >> S[i];
  }

  vi T(M);
  for (int i=0; i<M; i++) {
    cin >> T[i];
  }

  for (int i=0; i<N; i++) {
    if (S[i] == T[0]) {
      dp[i][0] = 1;
      sum[i][0] = 1;
    }
  }

  for (int j=0; j<M; j++) {
    if (S[0] == T[j]) {
      dp[0][j] = 1;
      sum[0][j] = 1;
    }
  }

  //dump();
  //cerr << endl;

  for (int j=0; j<M; j++) {
    for (int i=1; i<N; i++) {
      sum[i][j] += sum[i-1][j];
    }
  }

  for (int i=0; i<N; i++) {
    for (int j=1; j<M; j++) {
      sum[i][j] += sum[i][j-1];
    }
  }

  //dump();
  //cerr << endl;

  for (int i=1; i<N; i++) {

    for (int j=1; j<M; j++) {
      if (S[i] == T[j]) {
        addmod(dp[i][j], sum[i-1][j-1] + 1);
      }

      sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + MOD + dp[i][j])%MOD;
    }

  }

  cout << sum[N-1][M-1] + 1 << endl;

  return 0;
}


Measured memory_bytes: 62592