#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000;
const long long MOD = 1000000007;
int dp[110000];
int mx[110000];
int x[110000], y[110000], t[110000];
inline int dis(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int r, n, mmx = 0;
  cin >> r >> n;
  for (int i = 0; i < 110000; i++) dp[i] = -110000;
  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];
  for (int i = 1; i <= n; i++) {
    int tmp = -1;
    for (int j = i - 1; j >= 0; j--) {
      if (dis(i, j) <= t[i] - t[j]) dp[i] = max(dp[i], dp[j]);
      if (t[i] - t[j] > 1002) {
        tmp = j;
        break;
      }
    }
    if (tmp != -1) dp[i] = max(dp[i], mx[tmp]);
    if (dp[i] >= 0) dp[i] += 1;
    mmx = max(mmx, dp[i]);
    mx[i] = max(dp[i], mx[i - 1]);
  }
  cout << mmx << endl;
}
