#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
using namespace std;
int r, n, t[100005], x[100005], y[100005], dp[100005], ans[100005];
int cal(int a, int b) { return max(a - 1, r - a) + max(b - 1, r - b); }
int main() {
  cin >> r >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &t[i], &x[i], &y[i]);
  }
  t[0] = 0, x[0] = y[0] = 1;
  memset(dp, -1, sizeof(dp));
  dp[0] = ans[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (t[i] - t[j] >= cal(x[i], y[i])) {
        dp[i] = max(dp[i], ans[j] + 1);
        break;
      } else if (t[i] - t[j] >= abs(x[i] - x[j]) + abs(y[i] - y[j]) &&
                 dp[j] != -1) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    ans[i] = max(ans[i - 1], dp[i]);
  }
  printf("%d\n", ans[n]);
  return 0;
}
