#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9 + 9;
const int MAXN = 1000006;
const int C = 1000;
int n, r, x[MAXN], y[MAXN], t[MAXN];
int dp[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> r >> n;
  int acc = -INF, ans = 0;
  dp[0] = 0, x[0] = 1, y[0] = 1, t[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i] >> x[i] >> y[i];
    dp[i] = acc + 1;
    for (int j = max(0, i - C); j < i; ++j) {
      if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t[i] - t[j]) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    if (i >= C) acc = max(acc, dp[i - C]);
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
