#include <bits/stdc++.h>
using namespace std;
int r, n, m, a[100001], b[100001], t[100001], dp[100001], ans;
int main() {
  a[0] = 0;
  b[0] = 0;
  cin >> r >> n;
  for (int i = 1; i <= n; i++) {
    dp[i] = -n;
    scanf("%d%d%d", &t[i], &a[i], &b[i]);
    a[i]--;
    b[i]--;
    for (int j = i - 1; j >= max(0, i - 2000); j--) {
      if (t[i] - t[j] >= abs(a[i] - a[j]) + abs(b[i] - b[j]))
        dp[i] = max(dp[i], dp[j] + 1);
    }
    ans = max(ans, dp[i]);
  }
  cout << ans;
}
