#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long double PI = 3.14159265;
using ll = long long;
const ll modo = 1e9 + 7;
const ll ms = 1e6 + 5;
const ll inf = 1e17;
int ar[ms][3];
int dp[ms] = {0};
int mx[ms] = {0};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int i;
  dp[0] = 1;
  mx[0] = 1;
  ar[0][0] = 0;
  ar[0][1] = 1;
  ar[0][2] = 1;
  for (i = 1; i <= m; i++) {
    cin >> ar[i][0] >> ar[i][1] >> ar[i][2];
  }
  int j;
  int d;
  int t;
  for (i = 1; i <= m; i++) {
    if (i <= 1000) {
      for (j = 0; j < i; j++) {
        if (!dp[j]) continue;
        t = ar[i][0] - ar[j][0];
        d = abs(ar[i][1] - ar[j][1]) + abs(ar[i][2] - ar[j][2]);
        if (t >= d) dp[i] = max(dp[i], dp[j] + 1);
      }
    } else {
      int lim = i - 1000;
      dp[i] = mx[lim - 1] + 1;
      for (j = lim; j < i; j++) {
        if (!dp[j]) continue;
        t = ar[i][0] - ar[j][0];
        d = abs(ar[i][1] - ar[j][1]) + abs(ar[i][2] - ar[j][2]);
        if (t >= d) dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    mx[i] = max(mx[i - 1], dp[i]);
  }
  int ans = 0;
  for (i = 0; i <= m; i++) ans = max(ans, dp[i]);
  cout << ans - 1;
  return 0;
}
