/*
Problem link:
Tags:
*/
#include<bits/stdc++.h>
using namespace std;
//#define MULTI
#define ll long long
#define all(x) (x).begin(), (x).end()
void solve() {
ll n, r;
cin >> n >> r;
vector<vector<ll>> pos(n, vector<ll>(4));
map<ll, ll> times;
for (int i = 0; i < n; i++)
{
cin >> pos[i][0] >> pos[i][1] >> pos[i][2] >> pos[i][3];
ll kx = pos[i][2]-pos[i][0];
ll ky = pos[i][3]-pos[i][1];
ll a = pow(kx, 2) + pow(ky, 2);
ll b = 2*(kx*pos[i][0] + ky*pos[i][1]);
ll c = pow(pos[i][0], 2) + pow(pos[i][1], 2) - pow(r, 2);
ll D = pow(b, 2) - 4*a*c;
if(D < 0) continue;
ll t1 = ceil((-b - (long double)sqrt(D))/2.0/a);
ll t2 = floor((-b + (long double)sqrt(D))/2.0/a);
if(t1 < 0 || t2 < 0 || t2 < t1) continue;
times[t1]++;
times[t2+1]--;
}
ll mx = 0, cur = 0;
for(auto i: times) {
cur += i.second;
mx = max(mx, cur);
}
cout << mx << "\n";
}
int main(int argc, char **argv)
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef MULTI
int t;
cin >> t;
while (t--)
{
solve();
}
#else
solve();
#endif
return 0;
}