#include <bits/stdc++.h>
using namespace std;
struct Celeb {
  int x, y, t;
  Celeb(int x, int y, int t) {
    this->x = x;
    this->y = y;
    this->t = t;
  }
};
int time_dist(Celeb &a, Celeb &b) { return abs(a.x - b.x) + abs(a.y - b.y); }
bool can_extend(Celeb &a, Celeb &b) { return (b.t - a.t) >= time_dist(a, b); }
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  int n, r;
  cin >> r >> n;
  vector<Celeb> celebs;
  celebs.emplace_back(1, 1, 0);
  for (int i = 0; i < n; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    celebs.emplace_back(x, y, t);
  }
  vector<int> dp(n + 1, -1);
  dp[0] = 0;
  int res = 0;
  vector<int> dp2(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    int prevbefore = -1;
    if (i - 2 * r >= 0) {
      prevbefore = dp2[i - 2 * r];
    }
    for (int j = max(i - 2 * r, 0); j < i; j++) {
      if (dp[j] < 0) continue;
      if (can_extend(celebs[j], celebs[i])) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    if (prevbefore >= 0) {
      dp[i] = max(dp[i], prevbefore + 1);
    }
    res = max(res, dp[i]);
    dp2[i] = res;
  }
  cout << res << "\n";
  return 0;
}
