#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e18;
long long r, n;
long long t[100005], x[100005], y[100005];
long long ans[100005];
long long tt[1000005];
long long mx[1000005];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> r >> n;
  t[0] = 0, x[0] = 1, y[0] = 1;
  long long ii = 0;
  tt[0] = 0;
  for (long long i = 1; i < n + 1; i++) {
    ans[i] = -mod;
    cin >> t[i] >> x[i] >> y[i];
    mx[ii] = max(ans[i - 1], mx[ii]);
    while (ii < t[i]) {
      tt[ii] = i - 1;
      ii++;
      mx[ii] = mx[ii - 1];
    }
    long long val = tt[max(0ll, t[i] - 1 - 2000)];
    for (long long j = i - 1; j >= val; j--) {
      if (abs(x[j] - x[i]) + abs(y[j] - y[i]) <= t[i] - t[j]) {
        ans[i] = max(ans[i], ans[j] + 1);
      }
    }
  }
  long long answer = 0;
  for (long long i = 0; i < n + 1; i++) {
    answer = max(answer, ans[i]);
  }
  cout << answer << '\n';
  return 0;
}
