#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int r, n;
  cin >> r >> n;
  long long int t[100009], x[100009], y[100009];
  for (long long int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];
  long long int maxi[100009];
  maxi[0] = 0;
  long long int ans = 0;
  long long int mmaxi[100009];
  mmaxi[n + 1] = 0;
  t[0] = 0;
  x[0] = 1;
  y[0] = 1;
  for (long long int i = n; i >= 1; i--) {
    long long int j = i, td = 0;
    maxi[i] = 0;
    while (td < 2 * r && j <= n - 1) {
      j++;
      td += t[j] - t[j - 1];
      long long int dis = abs(x[i] - x[j]) + abs(y[i] - y[j]);
      if (dis <= td) maxi[i] = max(maxi[j], maxi[i]);
    }
    j++;
    maxi[i] = max(mmaxi[j], maxi[i]);
    maxi[i]++;
    mmaxi[i] = max(maxi[i], mmaxi[i + 1]);
  }
  for (long long int i = 1; i <= n; i++) {
    long long int dis = abs(x[i] - 1) + abs(y[i] - 1);
    if (dis <= t[i]) ans = max(ans, maxi[i]);
  }
  cout << ans;
}
