Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		dat := make([]Dat, m)
		for i := 0; i < m; i++ {
			dat[i] = Dat{io.NextInt(), io.NextInt(), io.NextInt()}
		}
		sort.Slice(dat, func(i, j int) bool { return dat[i].t < dat[j].t })
		infected := make([]bool, n+1)
		infected[1] = true
		for i := 0; i < m; i++ {
			infected[dat[i].d] = infected[dat[i].d] || infected[dat[i].s]
		}
		cnt := 0
		for i := 0; i <= n; i++ {
			if infected[i] {
				cnt++
			}
		}
		io.Println(cnt)
	}
}

type Dat struct {
	t, s, d int
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		bool infect[n+1];
		rep(i,n+1)infect[i]=false;
		infect[1]=true;
		long long ans=1;
		long long t[m];
		int s[m],d[m];
		rep(i,m)cin>>t[i]>>s[i]>>d[i];
		for(int i=m;i>=0;i--){
			for(int j=0;j<i-1;j++){
				if(t[j]>t[j+1]){
					long long alt=t[j];
					t[j]=t[j+1];
					t[j+1]=alt;
					alt=s[j];
					s[j]=s[j+1];
					s[j+1]=alt;
					alt=d[j];
					d[j]=d[j+1];
					d[j+1]=alt;
				}
			}
		}
		rep(i,m){
			if(infect[s[i]]){
				ans++;
				infect[d[i]]=true;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct edge{
  int t;
  int from;
  int to;
  edge(){};
  edge(int t,int from,int to):t(t),from(from),to(to){};
  bool operator<(const edge& other) const {
	return t < other.t;
  }
};

int main(){
  int n,m;
  while(cin >> n >> m && n != 0){
	vector<edge> vec;
	for(int i = 0;i < m;i++){
	  int t,f,to;
	  cin >> t >> f >> to;
	  vec.emplace_back(t,f,to);
	}
	sort(vec.begin(),vec.end());
	vector<bool> infected(n,false);
	infected[0] = true;
	for(int i = 0;i < m;i++){
	  int to,from;
	  to = vec[i].to;
	  from = vec[i].from;
	  if(infected[from-1])infected[to-1] = true;
	}
	int res = 0;
	for(int i = 0;i < n;i++){
	  if(infected[i])res++;
	}
	cout << res << endl;
	
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
	int n,m;
	int t,s,d;
	int cnt;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		map<int,pair<int,int> > mp;
		vector<bool> v(n);

		for(int i1=0;i1<n;i1++) v[i1]=false;
		v[0]=true;

		for(int i1=0;i1<m;i1++){
			cin>>t>>s>>d;
			mp[t]=make_pair(s-1,d-1);
		}

		cnt=1;
		for(map<int,pair<int,int> >::iterator it=mp.begin();it!=mp.end();it++){
			if(v[(*it).second.first] && !v[(*it).second.second]) {
				v[(*it).second.second]=true;
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	int[] par;
	int count;

	void union(int x, int y) {
		x = root(x);
		y = root(y);
		par[x] = y;
	}

	boolean find(int x, int y) {
		return root(x) == root(y);
	}

	int root(int x) {
		if (par[x] == x) return x;
		return root(par[x]);
	}

	class Data implements Comparable<Data>{
		int t, u, v;

		Data(int t, int u, int v) {
			this.t = t;
			this.u = u;
			this.v = v;
		}

		@Override
		public int compareTo(Data o) {
			return this.t - o.t;
		}
	}

	void run() {
		MyScanner sc = new MyScanner();

		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if ((n | m) == 0) {
				break;
			}
			Data[] d = new Data[m];
			for (int i = 0; i < m; i++) {
				d[i] = new Data(sc.nextInt(), sc.nextInt() - 1, sc.nextInt() - 1);
			}
			Arrays.sort(d);
			par = new int[n];
			for (int i = 0; i < n; i++) {
				par[i] = i;
			}

			count = 1;
			for (int i = 0; i < m; i++) {
				int t = d[i].t;
				int u = d[i].u;
				int v = d[i].v;

				if (find(0, u)) {
					union(u, v);
					count++;
				}
			}

			System.out.println(count);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}