#include <bits/stdc++.h>
// #define int long long
using namespace std;
const int N = 1e5 + 10, M = N;
int h[N], e[M], ne[M], idx;
int d[N], maxn[N], minn[N], cnt[N];
int root, ans, n;
void add(int a, int b) // 添加一条边a->b
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
void dfs(int u, int fa)
{
cnt[u] = 1;
maxn[u] = u;
minn[u] = u;
for (int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if (j == fa) continue;
dfs(j, u);
maxn[u] = max(maxn[u], maxn[j]);
minn[u] = min(minn[u], minn[j]);
cnt[u] += cnt[j];
}
if (cnt[u] == maxn[u] - minn[u] + 1)
{
ans ++ ;
}
}
signed main()
{
memset(h, -1, sizeof h);
cin >> n;
int a, b;
for (int i = 1; i < n; i ++ )
{
cin >> a >> b;
add(a, b), d[b] ++ ;
}
for (int i = 1; i <= n; i ++ )
{
if (d[i] == 0)
{
root = i;
break;
}
}
dfs(root, -1);
cout << ans << endl;
return 0;
}