#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

const lint mod = MOD9;
class mint{
    public:
        long long x;

    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend istream& operator>>(istream& is, mint& m){
        long long x; is >> x; m = x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

mint fac[MAX], facinv[MAX], inv[MAX];
void minit(){
    fac[0] = fac[1] = 1;
    facinv[0] = facinv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
        inv[i] = -mint(mod / i)*inv[mod % i];
        facinv[i] = facinv[i - 1] * inv[i];
    }   
}
mint mcomb(lint a, lint b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * facinv[b] * facinv[a - b];
}
mint mperm(lint a, lint b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * facinv[a - b];
}

int main(){
    lint N,K; cin>>N>>K;
    vector<vector<mint> > a(N, vector<mint>(K+1));
    rep(i, N) cin >> a[i][1];
    rep(i, N) rep(k, K+1){
        if(k==0) a[i][k] = 1;
        else if(k==1) continue;
        else a[i][k] = a[i][k-1] * a[i][1];
    }

    minit();
    vector<mint> b(K+1, 0);
    rep(k, K+1){
        rep(i, N) b[k] += a[i][k];
        b[k] /= fac[k];
    }

    mint d = 2;
    repn(x, K){
        mint c(0), ans(0);
        rep(i, N) c += d * a[i][x]; d *= 2;
        rep(k, x+1) ans += b[k] * b[x-k];
        ans = (ans * fac[x] - c) / mint(2);
        out(ans); 
    }
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

int main(){
  ll n,l;cin >> n >> l;l++;
  ll left=0;
  vl a(n+1),b(n+1);
  rep(i,n){
    ll t;cin >> t;
    a[i]=t-left-1;left=t;
  }
  a[n]=l-left-1;
  left=0;
  rep(i,n){
    ll t;cin >> t;
    b[i]=t-left-1;left=t;
  }
  b[n]=l-left-1;
  left=0;
  //rep(i,n+1)cout << a[i] <<" ";cout << endl;
  //rep(i,n+1)cout << b[i] <<" ";cout << endl;
  ll ans=0;
  ll start=0;
  rep(i,n+1){
    if(b[i]==0)continue;
    ll sum=0;
    ll left=-1,right=-1;
    for(int j=start;j<=n;j++){
      if(a[j]){
        if(left==-1)left=j;
        sum+=a[j];
        if(sum>b[i])break;
        if(sum==b[i]){
          right=j;break;
        }
      }
    }
    //cout << left <<" " << right <<endl;
    if(right==-1)cout << -1 <<endl,exit(0);
    if(left<=i&&i<=right)ans+=right-left;
    else if(i<left){
      ans+=right-i;
    }
    else{
      ans+=i-left;
    }
    start=right+1;
  }
  cout << ans <<endl;

} 
