const fi='coins.inp';
        fo='coins.out';
        maxn=100000;
var a,b,c:array[1..maxn]of longint;
        n,m,kq:longint;
procedure docf;
var f:text;
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,n,m);
        for i:=1 to n do read(f,a[i]);
        readln(f);
        for i:=1 to n do read(f,b[i]);
        for i:=1 to n do c[i]:=b[i]-a[i];
        close(f);
end;
procedure sort(l,r:longint);
var u,v,x,t:LONGINT;
begin
        u:=l;v:=r;x:=c[l+random(r-l+1)];
        repeat
        while c[u]<x do inc(u);
        while c[v]>x do dec(v);
        if u<=v then
        begin
                t:=c[u];c[u]:=c[v];c[v]:=t;
                t:=a[u];a[u]:=a[v];a[v]:=t;
                t:=b[u];b[u]:=b[v];b[v]:=t;
                inc(u);dec(v);
        end;
        until u>v;
        if l<v then sort(l,v);
        if U<R THEN sort(u,r);
end;
procedure xuly;
var i,j,k:longint;
begin
        sort(1,n);
        kq:=m;
        for i:=1 to n do
                if c[i]<=kq then kq:=b[i]+(kq-c[i]) else break;
end;
procedure xuat;
var f:text;
begin
        assign(f,fo);
        rewrite(f);
        writeln(f,kq);
        close(f);
end;
begin
        docf;
        xuly;
        xuat;
end.
