#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long r, n;
  cin >> r >> n;
  vector<long long> t(n);
  vector<long long> x(n);
  vector<long long> y(n);
  vector<vector<long long>> g(n + 1);
  for (long long i = 0; i < n; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  for (long long i = 0; i < n; i++) {
    long long dist = x[i] - 1 + y[i] - 1;
    if (t[i] < dist) g[0].push_back(i + 1);
    for (long long j = i + 1; j < n; j++) {
      if (t[j] - t[i] >= 1047) break;
      long long dist = abs(x[i] - x[j]) + abs(y[i] - y[j]);
      if (t[i] + dist > t[j]) g[i + 1].push_back(j + 1);
    }
  }
  vector<long long> longest(n + 1, 0);
  vector<bool> nb(n + 2, false);
  set<pair<long long, long long>> best;
  for (long long i = n; i >= 0; i--) {
    for (long long x : g[i]) {
      nb[x] = true;
    }
    for (pair<long long, long long> p : best) {
      if (!nb[p.second]) {
        longest[i] = -p.first + 1;
        break;
      }
    }
    best.insert({-longest[i], i});
    for (long long x : g[i]) nb[x] = false;
  }
  cout << longest[0] << '\n';
}
