#include <bits/stdc++.h>
const int MAGIC = 4000;
bool is_connected(const std::tuple<int, int, int> &i,
                  const std::tuple<int, int, int> &j) {
  int itime, ix, iy, jtime, jx, jy;
  std::tie(itime, ix, iy) = i;
  std::tie(jtime, jx, jy) = j;
  int distance = std::abs(ix - jx) + std::abs(iy - jy);
  int limit = std::abs(itime - jtime);
  return distance <= limit;
}
int32_t main() {
  int r, n;
  scanf("%d%d", &r, &n);
  n++;
  std::vector<std::tuple<int, int, int>> celebs(n);
  celebs[0] = std::make_tuple(0, 1, 1);
  for (int i = 1; i < n; i++) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    celebs[i] = std::make_tuple(t, x, y);
  }
  std::sort(celebs.begin(), celebs.end());
  std::vector<int> dp(n, 1);
  dp[0] = 0;
  for (int i = n - 1; i > 0; i--) {
    for (int j = std::max(i - MAGIC, 0); j < i; j++) {
      if (is_connected(celebs[i], celebs[j])) {
        dp[j] = std::max(dp[j], dp[i] + (j > 0));
      }
    }
  }
  printf("%d\n", dp[0]);
  return 0;
}
