public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] nb = readInts(line);
			int n = nb[0], b = nb[1];
			if (n == 0 && b == 0)
				break;
			inint(n);
			for (int i = 0; i < b; i++) {
				int[] box = readInts(in.readLine());
				int u = box[0] - 1, v = box[1] - 1, w = box[2];
				d[u][v] = Math.min(d[u][v], -w);
				d[v][u] = Math.min(d[v][u], w);
			}
			floyd(n);
			boolean cycle = false;
			for (int i = 0; i < n && !cycle; i++)
				cycle |= d[i][i] < 0;
			out.append(cycle ? "Y\n" : "N\n");
		}
		System.out.print(out);
	}