#include <bits/stdc++.h>
using namespace std;
int N, M, G[105][105], d[105][105];
bool F[105][105];
void wf() {
  for (int k = 0; k < N; k++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) {
        int t = -1;
        if (G[i][j] > G[i][k] + G[k][j]) {
          t = k;
          G[i][j] = G[i][k] + G[k][j];
        }
        G[i][k] = G[k][i] = G[k][j] = G[j][k] = false;
      }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) d[i][j] = i == j ? 0 : 100000000;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    G[a][b] = G[b][a] = c;
    F[a][b] = G[b][a] = 1;
  }
  wf();
  int res = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) res += F[i][j];
  printf("%d\n", res % 2);
}
