#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
T &ctmax(T &x, const U &y) {
  return x = max<T>(x, y);
}
template <class T, class U>
T &ctmin(T &x, const U &y) {
  return x = min<T>(x, y);
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(ios::badbit | ios::failbit);
  int r, n;
  cin >> r >> n;
  vector<int> t(n + 1), x(n + 1), y(n + 1);
  x[0] = 1, y[0] = 1;
  for (auto i = 1; i <= n; ++i) {
    cin >> t[i] >> x[i] >> y[i];
  }
  auto dist = [&](int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); };
  vector<int> dp(n + 1, -1);
  vector<int> lazy(n + 1, -1);
  dp[0] = 0;
  for (auto i = 0; i <= n; ++i) {
    if (i) {
      ctmax(lazy[i], lazy[i - 1]);
    }
    ctmax(dp[i], lazy[i]);
    if (~dp[i]) {
      int j = i + 1;
      for (; j <= n && t[j] <= t[i] + 2 * r - 2; ++j) {
        if (dist(i, j) <= t[j] - t[i]) {
          ctmax(dp[j], dp[i] + 1);
        }
      }
      if (j <= n) {
        ctmax(lazy[j], dp[i] + 1);
      }
    }
  }
  42;
  42;
  cout << *max_element(dp.begin(), dp.end()) << "\n";
  return 0;
}
