#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pl pair<ll,ll>
#define x first
#define y second
const ll N=5e5+10;
pl f[N],s[N],inc[N];
ll n,r;
bool check(int i,int p)
{
ll fx=(f[i].x+inc[i].x*p);
ll fy=(f[i].y+inc[i].y*p);
// fx*fx+2*fx*ix*p+ix*ix*p*p
// fy*fy+2*fy*iy*p+iy*iy*p*p
return (fx*fx+fy*fy)<=(r*r);
}
pair<ld,ld> RTF(ld a,ld b,ld c)
{
ld pp=b*b-a*c*4;
if(pp<0)
{
return {1e9,-1e9};
}
pp=sqrtl(pp);
ld r1=(-b-pp)/(a*2);
ld r2=(-b+pp)/(a*2);
if(r2<r1)
swap(r1,r2);
return {r1,r2};
}
void solve()
{
cin>>n>>r;
map<ll,ll> dif;
ld eps=1/(1e9);
for(int i=1;i<=n;i++)
{
cin>>f[i].x>>f[i].y>>s[i].x>>s[i].y;
inc[i].x=(s[i].x-f[i].x);
inc[i].y=(s[i].y-f[i].y);
ll A=inc[i].x*inc[i].x+inc[i].y*inc[i].y;
ll B=f[i].x*inc[i].x+f[i].y*inc[i].y;
B=2*B;
ll C=f[i].x*f[i].x+f[i].y*f[i].y-r*r;
pair<ld,ld> roots=RTF(A,B,C);
// -b +- sqrtl()
// cout<<"Equation "<<A<<' '<<B<<' '<<C<<endl;
// if(roots.first==1e9 and roots.second==-1e9) // this can never contribute to answer
// {
// continue;
// }
// ld zero=0.000;
// if(roots.second<zero)
// {
// continue;
// }
// if(roots.first<zero)
// {
// roots.first=zero;
// }
ll rl=ceil(roots.first),rr=floor(roots.second);
rl=max(rl,0ll);
if(rl<=rr)
{
dif[rl]++;
dif[rr+1]--;
}
// cout<<roots.first<<' '<<roots.second<<endl;
// cout<<rl<<' '<<rr<<endl;
// dif[roots.first]++;
// dif[roots.second+eps]--;
}
ll pr=0;
ll mx=0;
for(auto it:dif)
{
pr+=it.second;
mx=max(mx,pr);
}
cout<<mx<<endl;
// int as=0;
// for(int p=0;p<=2e4;p++)
// {
// int ans=0;
// for(int i=1;i<=n;i++)
// {
// ans+=check(i,p);
// }
// as=max(as,ans);
// }
// cout<<as<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}