#include <bits/stdc++.h>
using namespace std;
int r, n;
const int N = 1e6 + 5;
struct Person {
  int x, y, t;
} st[N];
int Dis(const Person &a, const Person &b) {
  return abs(a.x - b.x) + abs(a.y - b.y);
}
int h;
int f[N];
int ans = 0;
int main() {
  scanf("%d%d", &r, &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &st[i].t, &st[i].x, &st[i].y);
  st[0].x = st[0].y = 1;
  st[0].t = 0;
  h = 0;
  int pmx = -1e9;
  for (int i = 1; i <= n; i++) {
    while (st[i].t - st[h].t >= 2 * r) {
      pmx = max(pmx, f[h]);
      h++;
    }
    int mx = pmx;
    for (int j = h; j < i; j++) {
      if (Dis(st[i], st[j]) <= st[i].t - st[j].t) mx = max(mx, f[j]);
    }
    f[i] = mx + 1;
    ans = max(ans, f[i]);
  }
  cout << ans;
  return 0;
}
