#include <bits/stdc++.h>

int main(){
    int n, l;
    std::cin >> n >> l;
    std::vector<std::pair<int, int>> vec(n + 2);
    vec[0] = std::make_pair(0, 0);
    vec[n + 1] = std::make_pair(l - n, l - n);
    for(int i = 1; i <= n; i++) std::cin >> vec[i].first, vec[i].first -= i;
    for(int i = 1; i <= n; i++) std::cin >> vec[i].second, vec[i].second -= i;
    long long res = 0;

    for(int i = 1; i <= n;){
        if(vec[i].first < vec[i].second){
            int iter = std::lower_bound(vec.begin() + i, vec.end(), std::make_pair(vec[i].second, -1)) - vec.begin();

            if(vec[i].second == vec[iter].first){
                res += (long long)(iter - i);
                while(i < iter && vec[i].second == vec[iter].first){
                    vec[i].first = vec[i].second;
                    i++;
                }
            }
            else{
                std::cout << "-1\n";
                return 0;
            }
        }
        else i++;
    }

    for(int i = n; i >= 1;){
        if(vec[i].first > vec[i].second){
            int iter = std::upper_bound(vec.begin() + 1, vec.begin() + i + 1, std::make_pair(vec[i].second, 0x7f7f7f7f)) - vec.begin();
            iter--;

            if(vec[i].second == vec[iter].first){
                res += (long long)(i - iter);
                while(i > iter && vec[i].second == vec[iter].first){
                    vec[i].first = vec[i].second;
                    i--;
                }
            }
            else{
                std::cout << "-1\n";
                return 0;
            }
        }
        else i--;
    }

    std::cout << res << "\n";
}

#include<bits/stdc++.h>
using namespace std;
    #define author          "Sihare0riginals"
    #define ss              string 
    #define lli             long long int
    #define ld              long double
    #define f               first
    #define s               second
    #define all(v)          v.begin(),v.end()
    #define I(a,i)          memset(a,i,sizeof(a));
    #define pb              push_back
    #define mp              make_pair
    #define L(i,start,end)  for(lli i=start;i<=end;i++)
    #define R(i,start,end)  for(lli i=start;i>=end;i--)
    #define ip(n)           cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i];
const lli LINF = 1e18,mod=1e9+7;
void Bl0ck_M0mb0();
 
 
signed main()
{
    Bl0ck_M0mb0();
    lli t=1;
    //cin>>t;
    while(t--){
      lli n,x;
      cin>>n>>x;
      x*=100;
      lli ip[n+1],ans=0,res=-1;
      L(i,1,n)
      {
        lli a,b;
        cin>>a>>b;
        ans+=a*b;
        if(ans>x)
        {
            res=i;
            break;
        }
      }  
      cout<<res<<endl;
    }
    return 0;
}





























void Bl0ck_M0mb0(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("ip.txt","r",stdin);
    freopen("op.txt","w",stdout);
    #endif
}
/*
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for(lli i=s1;i<=e1;i++){cout<<i<<"th :";for(lli j=s2;j<=e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}
#define M map<lli,lli> \n #define sz(s) s.size()-1
#define P pair<lli,lli> 
#define V vector<lli>
lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
    lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); } */