There are n cities and m roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.

What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?

New roads will also be one-way.

Input

The first line of input consists of three integers n, m and s (1 ≤ n ≤ 5000, 0 ≤ m ≤ 5000, 1 ≤ s ≤ n) — the number of cities, the number of roads and the index of the capital. Cities are indexed from 1 to n.

The following m lines contain roads: road i is given as a pair of cities u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i). For each pair of cities (u, v), there can be at most one road from u to v. Roads in opposite directions between a pair of cities are allowed (i.e. from u to v and from v to u).

Output

Print one integer — the minimum number of extra roads needed to make all the cities reachable from city s. If all the cities are already reachable from s, print 0.

Examples

Input

9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1


Output

3


Input

5 4 5
1 2
2 3
3 4
4 1


Output

1

Note

The first example is illustrated by the following:

<image>

For example, you can add roads (6, 4), (7, 9), (1, 7) to make all the cities reachable from s = 1.

The second example is illustrated by the following:

<image>

In this example, you can add any one of the roads (5, 1), (5, 2), (5, 3), (5, 4) to make all the cities reachable from s = 5.
#include <bits/stdc++.h>
const int N = 5010;
const long long INF = 1ll << 60;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
class Graph {
 public:
  void Init(int n) {
    e_.clear();
    e_.push_back(Edge(0, 0, 1, 0));
    m_ = 0;
    n_ = n;
    hd_.assign(n + 1, 0);
    vis_.assign(n + 1, false);
    connected_num_ = 0;
    for (int i = 1; i <= n; ++i) {
      deg_in_[i] = 0;
    }
  }
  void Init(int n, long long w[]) {
    e_.clear();
    e_.push_back(Edge(0, 0, 1, 0));
    m_ = 0;
    n_ = n;
    hd_.assign(n + 1, 0);
    vis_.assign(n + 1, false);
    connected_num_ = 0;
    for (int i = 1; i <= n; ++i) {
      deg_in_[i] = 0;
      weight[i] = w[i];
    }
  }
  void Add(int u, int v, long long w = 1ll, int type = 0) {
    Edge edge(v, hd_[u], w, type);
    e_.push_back(edge);
    hd_[u] = ++m_;
    ++deg_in_[v];
  }
  int Head(int id_v) { return hd_[id_v]; }
  int Next(int id_e) { return e_[id_e].nxt; }
  int To(int id_e) { return e_[id_e].v; }
  long long& W(int id_e) { return e_[id_e].w; }
  int& Type(int id_e) { return e_[id_e].type; }
  int NumNode() { return n_; }
  long long WNode(int u) { return weight[u]; }
  void Build(int st) { Dfs(st); }
  std::vector<bool> vis_;

 private:
  struct Edge {
    int v, nxt;
    long long w;
    int type;
    Edge(int _v, int _nxt, long long _w, int _type)
        : v(_v), nxt(_nxt), w(_w), type(_type) {}
  };
  void Dfs(int u) {
    vis_[u] = true;
    for (int i = Head(u); i; i = Next(i)) {
      int v = To(i);
      if (!vis_[v]) Dfs(v);
    }
  }
  int n_;
  std::vector<int> hd_;
  long long weight[N];
  int m_;
  std::vector<Edge> e_;
  int deg_in_[N];
  int connected_num_;
} graph, graph2;
class StrongConnection {
 public:
  void Init(int n, int m) {
    n_ = n;
    m_ = m;
    cnt_bicon = 0;
    dfs_time = 0;
    for (int i = 1; i <= n; ++i) {
      id[i] = 0;
      w[i] = 0ll;
      dfn[i] = 0;
      deg[i] = 0;
    }
    while (!sta.empty()) {
      sta.pop();
    }
  }
  int NumberZeroDegree(Graph& graph) {
    for (int i = 1; i <= n_; ++i) {
      if (!dfn[i]) {
        Dfs(graph, i);
      }
    }
    ma.clear();
    for (int u = 1; u <= n_; ++u) {
      for (int i = graph.Head(u); i; i = graph.Next(i)) {
        int v = graph.To(i);
        if (id[v] != id[u]) {
          int x = id[u];
          int y = id[v];
          if (ma.find(std::pair<int, int>(x, y)) == ma.end()) {
            ++deg[y];
            ma[std::pair<int, int>(x, y)] = true;
          }
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= cnt_bicon; ++i)
      if (!deg[i]) ++ans;
    return ans;
  }
  int Id(int u) { return id[u]; }
  int NodeSize(int id) { return bicons[id].size(); }
  int NumNode() { return cnt_bicon; }
  int deg[N];

 private:
  void Dfs(Graph& graph, int u) {
    dfn[u] = ++dfs_time;
    low[u] = dfn[u];
    sta.push(u);
    for (int i = graph.Head(u); i; i = graph.Next(i)) {
      int v = graph.To(i);
      if (!dfn[v]) {
        Dfs(graph, v);
        low[u] = std::min(low[u], low[v]);
      } else if (!id[v]) {
        low[u] = std::min(low[u], dfn[v]);
      }
    }
    if (low[u] == dfn[u]) {
      ++cnt_bicon;
      bicons[cnt_bicon].clear();
      int tmp;
      do {
        tmp = sta.top();
        sta.pop();
        id[tmp] = cnt_bicon;
        bicons[cnt_bicon].push_back(tmp);
        w[cnt_bicon] += graph.WNode(tmp);
      } while (tmp != u);
    }
  }
  int n_;
  int dfs_time;
  int dfn[N];
  int low[N];
  int id[N];
  std::stack<int> sta;
  int cnt_bicon;
  long long w[N];
  std::vector<int> bicons[N];
  std::map<std::pair<int, int>, bool> ma;
  int m_;
} strong_con;
int t;
int n, m, s;
int a[N];
int b[N];
int main() {
  scanf("%d%d%d", &n, &m, &s);
  graph.Init(n);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    graph.Add(a[i], b[i]);
  }
  graph.Build(s);
  int ans1 = 0;
  for (int i = 1; i <= n; ++i) {
    if (graph.vis_[i]) ++ans1;
  }
  graph2.Init(n);
  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    if (!graph.vis_[a[i]] && !graph.vis_[b[i]]) {
      graph2.Add(a[i], b[i]);
      ++cnt;
    }
  }
  strong_con.Init(n, cnt);
  int ans = strong_con.NumberZeroDegree(graph2) - ans1;
  printf("%d\n", ans);
  return 0;
}
