#include <bits/stdc++.h>
using namespace std;
const int mxeN = 1e5 + 10;
long long dp[mxeN];
int r, n;
vector<tuple<int, int, int> > v(mxeN);
long long dfs(int idx) {
  if (idx > n) {
    return 0;
  }
  if (dp[idx] != 0) {
    return dp[idx];
  }
  int difT;
  int difDis;
  for (int i = idx + 1; i <= min(n, idx + 4 * r + 3); i++) {
    difT = get<0>(v[i]) - get<0>(v[idx]);
    difDis =
        abs(get<1>(v[i]) - get<1>(v[idx])) + abs(get<2>(v[i]) - get<2>(v[idx]));
    if (difT >= difDis) {
      dp[idx] = max(dp[idx], 1 + dfs(i));
    }
    if (dp[idx] > n - idx + 1) {
      break;
    }
  }
  return dp[idx];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> r >> n;
  int a, b, c;
  v[0] = make_tuple(0, 1, 1);
  for (int i = 1; i <= n; i++) {
    cin >> a >> b >> c;
    auto tup = make_tuple(a, b, c);
    v[i] = tup;
  }
  long long ans = 0;
  ans = dfs(0);
  cout << ans << endl;
  return 0;
}
