#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 1, M = 1e2 + 1, INF = 2e9, MOD = 1e9 + 7, L = 20,
                NN = 1e9 + 1;
long long t[N];
pair<long long, long long> mas[N];
long long dp[N];
long long prmax[N];
void solve() {
  long long r, n;
  cin >> r >> n;
  mas[0] = {1, 1};
  t[0] = 0;
  for (long long i = 1; i < n + 1; i++) {
    cin >> t[i];
    cin >> mas[i].first >> mas[i].second;
    dp[i] = -INF;
    for (long long j = i - 1; j >= 0; j--) {
      if (t[i] - t[j] > 1003) {
        dp[i] = max(dp[i], 1 + prmax[j]);
        break;
      }
      if (abs(mas[i].first - mas[j].first) +
              abs(mas[i].second - mas[j].second) <=
          t[i] - t[j]) {
        dp[i] = max(dp[i], 1 + dp[j]);
      }
    }
    prmax[i] = max(dp[i], prmax[i - 1]);
  }
  cout << prmax[n] << '\n';
}
signed main() {
  long long t = 1;
  while (t--) solve();
}
