There are n cities in the kingdom X, numbered from 1 through n. People travel between cities by some one-way roads. As a passenger, JATC finds it weird that from any city u, he can't start a trip in it and then return back to it using the roads of the kingdom. That is, the kingdom can be viewed as an acyclic graph.

Being annoyed by the traveling system, JATC decides to meet the king and ask him to do something. In response, the king says that he will upgrade some cities to make it easier to travel. Because of the budget, the king will only upgrade those cities that are important or semi-important. A city u is called important if for every city v ≠ u, there is either a path from u to v or a path from v to u. A city u is called semi-important if it is not important and we can destroy exactly one city v ≠ u so that u becomes important.

The king will start to act as soon as he finds out all those cities. Please help him to speed up the process.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 300 000, 1 ≤ m ≤ 300 000) — the number of cities and the number of one-way roads.

Next m lines describe the road system of the kingdom. Each of them contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), denoting one-way road from u_i to v_i.

It is guaranteed, that the kingdoms' roads make an acyclic graph, which doesn't contain multiple edges and self-loops.

Output

Print a single integer — the number of cities that the king has to upgrade.

Examples

Input

7 7
1 2
2 3
3 4
4 7
2 5
5 4
6 4


Output

4

Input

6 7
1 2
2 3
3 4
1 5
5 3
2 6
6 4


Output

4

Note

In the first example: 

<image>

  * Starting at the city 1 we can reach all the other cities, except for the city 6. Also, from the city 6 we cannot reach the city 1. Therefore, if we destroy the city 6 then the city 1 will become important. So 1 is a semi-important city. 
  * For city 2, the set of cities that cannot reach 2 and cannot be reached by 2 is \{6\}. Therefore, destroying city 6 will make the city 2 important. So city 2 is also semi-important. 
  * For city 3, the set is \{5, 6\}. As you can see, destroying either city 5 or 6 will not make the city 3 important. Therefore, it is neither important nor semi-important. 
  * For city 4, the set is empty. So 4 is an important city. 
  * The set for city 5 is \{3, 6\} and the set for city 6 is \{3, 5\}. Similarly to city 3, both of them are not important nor semi-important. 
  * The city 7 is important since we can reach it from all other cities. 

So we have two important cities (4 and 7) and two semi-important cities (1 and 2).

In the second example, the important cities are 1 and 4. The semi-important cities are 2 and 3.
import java.util.*;
import java.math.*;
import java.io.*;

// I hate this problem
public class CF1062F {
	class Graph {
		int n, cntfwd[], cntrev[], adj[][], rev[][];
		Deque<Integer> q;
		boolean[] visited;
		public Graph(int nn, int[][] edge) {
			n = nn;
			adj = new int[n][];
			rev = new int[n][];
			cntfwd = new int[n];
			cntrev = new int[n];
			for(int i = 0 ; i < edge[0].length ; i++) {
				cntfwd[edge[0][i]]++;
				cntrev[edge[1][i]]++;
			}
			for(int i = 0 ; i < n ; i++) {
				adj[i] = new int[cntfwd[i]];
				rev[i] = new int[cntrev[i]];
			}
			for(int i = 0 ; i < edge[0].length ; i++)
				add(edge[0][i], edge[1][i]);
			q = new ArrayDeque<>();
			visited = new boolean[n];
		}
		void add(int u, int v) {
			adj[u][--cntfwd[u]] = v;
			rev[v][--cntrev[v]] = u;
		}
		int solve() {

			int res = 0;

			/*

			All important nodes must lie on the longest path.

			Let u be an important node.
			Let path P = p[1] -> p[2] -> p[3] -> ... -> p[k]
			Assume P is the longest path and u is not on P.
			One of three cases will happen with u and P:

				1. u has a path to all p[i]. Because of this, the path Q can be constructed.
				   Q = u -> p[1] -> p[2] -> p[3] -> ... -> p[k].
				   Q is a longer path than P.

				2. All p[i] has a path to u. Because of this, the path Q can be constructed.
				   Q = p[1] -> p[2] -> p[3] -> ... -> p[k] -> u.
				   Q is a longer path than P.

				3. There is some p[i] that u does not have a path to and p[i + 1] that u has a path to. 
				   P can be partitioned into two pieces, p[1, i] and p[i + 1, k]. The path Q can be
				   constructed from these partitions, where u can be placed between them.
				   Q = p[1] -> p[2] -> p[3] -> ... -> p[i] -> u -> p[i + 1] -> ... -> p[k]
				   Q is a longer path than P.

			P is not the longest path in all cases. If there is a path that does not contain an important node,
			a longer path can always be constructed using the important node.

			Therefore, all important nodes must lie on the longest path.

			 */
			dp = new int[n];
			path = new int[n];
			Arrays.fill(dp, -1);
			Arrays.fill(path, -1);
			for(int i = 0 ; i < n ; i++)
				go(i);
			int maxpath = 0;
			int maxpathnode = -1;
			for(int i = 0 ; i < n ; i++) {
				if(dp[i] > maxpath) {
					maxpath = dp[i];
					maxpathnode = i;
				}
			}

			int[] p = new int[dp[maxpathnode] + 1];
			{
				int ind = 0;
				int u = maxpathnode;
				while(u != -1) {
					p[ind++] = u;
					u = path[u];
				}
			}

			/*

			To count all important nodes, we need to find the in[u] and out[u] for all nodes
			along P. in[u] will be the number of nodes that have a path to u, and out[u] will
			be the number of nodes u has a path to.

			for each i in P[1 : k]:
				Let u = p[i].

				BFS from u using the reverse edges of the graph, all nodes that u can reach using
				the reverse edges means that all those nodes can reach u using the normal edges.
				Only visit each node once, and keep count of the reachable nodes. Don't visit
				nodes on P.

				in[u] += reachableNodes.

				After that, add in the nodes from in[p[i - 1]] if u is not the first node in the path.
				Add an extra 1 to include the previous node as it reaches u.

				if i > 0: in[u] += in[p[i - 1]] + 1

			for each i in P[k : 1]:
				Let u = p[i].

				BFS from u using the normal edges of the graph. Only visit each node once, and keep
				count of the reachable nodes. Don't visit nodes on P.

				out[u] += reachableNodes.

				After that, add in the nodes of out[p[i + 1]] if u is not the last node in the path.
				Add an extra 1 to include the next node as reachable.

				if i < len(p): out[u] += out[p[i + 1]] + 1

			for each i in P[1 : k]
				Let u = p[i].

				If in[u] + out[u] is equal to n - 1, then u is an important node.
				If in[u] + out[u] is equal to n - 2, then u is a semi-important node.

			 */

			int[] in = new int[n];
			int[] out = new int[n];

			for(int i = 0 ; i < p.length ; i++)
				visited[p[i]] = true;
			for(int i = 0 ; i < p.length ; i++) {
				int reachableNodes = 0;
				q.add(p[i]);
				while(!q.isEmpty()) {
					int u = q.pop();
					for(int v : rev[u]) {
						if(!visited[v]) {
							visited[v] = true;
							q.add(v);
							reachableNodes++;
						}
					}
				}
				in[p[i]] += reachableNodes;
				if(i > 0) in[p[i]] += in[p[i - 1]] + 1;
			}
			Arrays.fill(visited, false);
			for(int i = 0 ; i < p.length ; i++)
				visited[p[i]] = true;
			for(int i = p.length - 1 ; i >= 0 ; i--) {
				int reachableNodes = 0;
				q.add(p[i]);
				while(!q.isEmpty()) {
					int u = q.pop();
					for(int v : adj[u]) {
						if(!visited[v]) {
							visited[v] = true;
							q.add(v);
							reachableNodes++;
						}
					}
				}
				out[p[i]] += reachableNodes;
				if(i < p.length - 1) out[p[i]] += out[p[i + 1]] + 1;
			}

			for(int i = 0 ; i < p.length ; i++)
				if(in[p[i]] + out[p[i]] >= n - 2)
					res++;

			/*

			All nodes along P are done, now the rest of the nodes must be dealt with.

			For all nodes u that are not in P, we need to determine whether they
			are semi-important or not. We will need to find candidates that might
			possibly be semi-important
			Let L[u] = p[i] = rightmost node from the left that can reach u
			Let R[u] = p[j] = leftmost node from the right that u can reach

			If for any u, j - i - 1 > 1, then u is not semi-important.
			Side-note* if j - i - 1 is 0, then u is on the longest path, so for u
			           to be semi-important, j - i - 1 must only be 1

			p[i] -> j - i - 1 nodes -> p[j]
			 |                          ^
			 |-----------> u -----------|

			 All the nodes on p that are between p[i] and p[j] are not reachable from u,
			 and u cannot reach any of them, so if there is more than 1 node along that path,
			 u cannot be semi-important.

			 If u does not fail this, add it to the candidates list.


			 If there are 2 candidate nodes, u and v, where L[v] = L[u]
			 (which also means R[v] = R[u]), then both u and v cannot be
			 candidates. Here are the cases:

			 Let d be the node in between p[i] and p[j].

			 p[i] -> d -> p[j]
			 | |           ^ ^
			 | |---> u ----| |
			 |               |
			 |-----> v ------|

			 In this case, d cannot be reached by u and u cannot be reached by d. This same
			 statement can be applied to v if d is replaced by v. Meaning there are at least
			 2 nodes that are both unreachable and do not reach u. Same goes for v.
			 u and v can be removed from the candidates list.

			 p[i] -> d -> p[j]
			  |            ^
			  |-> v --> u -|

			 p[i] -> d -> p[j]
			  |            ^
			  |-> u --> v -|

			 In these cases, u and v combined with P create a longer path than the already
			 established longest path, so these cases are impossible.

			 */

			int[] L = new int[n];
			int[] R = new int[n];
			Arrays.fill(L, -1);
			Arrays.fill(R, -1);
			Arrays.fill(visited, false);
			for(int i = 0 ; i < p.length ; i++)
				visited[p[i]] = true;
			for(int i = p.length - 1 ; i >= 0 ; i--) {
				q.add(p[i]);
				while(!q.isEmpty()) {
					int u = q.pop();
					for(int v : adj[u]) {
						if(!visited[v]) {
							visited[v] = true;
							L[v] = i;
							q.add(v);
						}
					}
				}
			}
			Arrays.fill(visited, false);
			for(int i = 0 ; i < p.length ; i++)
				visited[p[i]] = true;
			for(int i = 0 ; i < p.length ; i++) {
				q.add(p[i]);
				while(!q.isEmpty()) {
					int u = q.pop();
					for(int v : rev[u]) {
						if(!visited[v]) {
							visited[v] = true;
							R[v] = i;
							q.add(v);
						}
					}
				}
			}
			int[] candidate = new int[p.length];
			Arrays.fill(candidate, -1);
			boolean[] valid = new boolean[p.length];
			Arrays.fill(valid, true);
			for(int i = 0 ; i < n ; i++) {
				if(L[i] != -1 && R[i] != -1) {
					if(R[i] - L[i] - 1 == 1) {
						if(candidate[L[i]] != -1) {
							valid[L[i]] = false;
						} else {
							candidate[L[i]] = i;
						}
					}
				}
			}
			List<Integer> specialCase1 = new ArrayList<>();
			List<Integer> specialCase2 = new ArrayList<>();
			for(int i = 0 ; i < n ; i++) {
				if(L[i] == -1 && R[i] == 1)
					specialCase1.add(i);
				if(L[i] == p.length - 2 && R[i] == -1) 
					specialCase2.add(i);
			}
			for(int i = 0 ; i < p.length ; i++)
				if(valid[i] && candidate[i] == -1)
					valid[i] = false;

			/*

			All candidate nodes have some p[i] -> candidate[c] -> p[i + 2]. Because of this, the
			same process can be used to calculate the in[candidate[c]] and out[candidate[c]] that
			was used on all nodes in P. It's just that instead of starting the BFS at some p[i], it
			starts at candidate[c].

			 */
			
			Deque<Integer> unvisit = new ArrayDeque<>();
			Arrays.fill(in, 0);
			Arrays.fill(out, 0);
			Arrays.fill(visited, false);
			for(int i = 0 ; i < p.length ; i++)
				visited[p[i]] = true;
			for(int i = 0 ; i < p.length ; i++) {
				if(i > 0 && valid[i - 1]) {
					int reachableNodes = 0;
					q.add(candidate[i - 1]);
					visited[candidate[i - 1]] = true;
					while(!q.isEmpty()) {
						int u = q.pop();
						unvisit.add(u);
						for(int v : rev[u]) {
							if(!visited[v]) {
								visited[v] = true;
								q.add(v);
								reachableNodes++;
							}
						}
					}
					in[candidate[i - 1]] += reachableNodes;
					if(i > 0) in[candidate[i - 1]] += in[p[i - 1]] + 1;
					while(!unvisit.isEmpty())
						visited[unvisit.pop()] = false;
				}
				int reachableNodes = 0;
				q.add(p[i]);
				while(!q.isEmpty()) {
					int u = q.pop();
					for(int v : rev[u]) {
						if(!visited[v]) {
							visited[v] = true;
							q.add(v);
							reachableNodes++;
						}
					}
				}
				in[p[i]] += reachableNodes;
				if(i > 0) in[p[i]] += in[p[i - 1]] + 1;
			}

			Arrays.fill(visited, false);
			for(int i = 0 ; i < p.length ; i++)
				visited[p[i]] = true;
			for(int i = p.length - 1 ; i >= 0 ; i--) {
				if(i > 0 && valid[i - 1]) {
					int reachableNodes = 0;
					q.add(candidate[i - 1]);
					visited[candidate[i - 1]] = true;
					while(!q.isEmpty()) {
						int u = q.pop();
						unvisit.add(u);
						for(int v : adj[u]) {
							if(!visited[v]) {
								visited[v] = true;
								q.add(v);
								reachableNodes++;
							}
						}
					}
					out[candidate[i - 1]] += reachableNodes;
					if(i < p.length - 1) out[candidate[i - 1]] += out[p[i + 1]] + 1;
					while(!unvisit.isEmpty())
						visited[unvisit.pop()] = false;
				}
				int reachableNodes = 0;
				q.add(p[i]);
				while(!q.isEmpty()) {
					int u = q.pop();
					for(int v : adj[u]) {
						if(!visited[v]) {
							visited[v] = true;
							q.add(v);
							reachableNodes++;
						}
					}
				}
				out[p[i]] += reachableNodes;
				if(i < p.length - 1) out[p[i]] += out[p[i + 1]] + 1;
			}

			/*

			Lastly, for each candidate node, if in[candidate[i]] + out[candidate[i]] is n - 2, then
			candidate[i] is semi-important.

			 */

			for(int i = 0 ; i < p.length ; i++)
				if(valid[i])
					if(in[candidate[i]] + out[candidate[i]] == n - 2)
						res++;

			/*

			Oh, and there are gay special cases, like this:

			p[1] -> p[2] -> ... -> p[k]
			          ^
			          |
			candidate[c]
			
			All nodes that are in this special case are in list specialCase1


			Ahh, and this one:

			p[1] -> ... p[k - 1] -> p[k]
			                |
			                v
			                candidate[c]

			All nodes that are in this special case are int list specialCase2

			If there is more than 1 node in either special case list, then that whole
			special case list cannot work.

			 */
			
			res += specialCaseCheck(specialCase1) + specialCaseCheck(specialCase2);

			return res;
		}
		int specialCaseCheck(List<Integer> specialCases) {
			if(specialCases.size() != 1)
				return 0;
			int sc = specialCases.get(0);
			Arrays.fill(visited, false);
			visited[sc] = true;
			q.add(sc);
			int incnt = 0, outcnt = 0;
			while(!q.isEmpty()) {
				int u = q.pop();
				for(int v : adj[u]) {
					if(!visited[v]) {
						visited[v] = true;
						q.add(v);
						outcnt++;
					}
				}
			}
			Arrays.fill(visited, false);
			visited[sc] = true;
			q.add(sc);
			while(!q.isEmpty()) {
				int u = q.pop();
				for(int v : rev[u]) {
					if(!visited[v]) {
						visited[v] = true;
						q.add(v);
						incnt++;
					}
				}
			}
			if(incnt + outcnt == n - 2)
				return 1;
			return 0;
		}
		int[] dp, path;
		int go(int u) {
			if(dp[u] != -1) return dp[u];
			int res = 0;
			for(int v : adj[u]) {
				int tmp = go(v) + 1;
				if(tmp > res) {
					res = tmp;
					path[u] = v;
				}
			}
			dp[u] = res;
			return res;
		}
	}
	public CF1062F() {
		FS scan = new FS();
		int n = scan.nextInt(), e = scan.nextInt();
		int[][] edge = new int[2][e];
		for(int i = 0 ; i < e ; i++) {
			edge[0][i] = scan.nextInt() - 1;
			edge[1][i] = scan.nextInt() - 1;
		}
		Graph g = new Graph(n, edge);
		System.out.println(g.solve());
	}
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() {
			while(!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) { e.printStackTrace(); }
			}
			return st.nextToken();
		}
		public int nextInt() { return Integer.parseInt(next()); }
	}
	public static void main(String[] args) { new CF1062F(); }
}
/*

10 10
1 2
2 3
4 2
4 3
5 4
6 4
3 7
7 8
7 9
7 10
  0 -> 1
  1 -> 2
  3 -> 1
  3 -> 2
  4 -> 3
  5 -> 3
  2 -> 6
  6 -> 7
  6 -> 8
  6 -> 9

 */