#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>


using namespace std;
using ll=long long;
const ll inf = 1e6;

vector<vector<ll>>g(2001);
ll p[4000];
int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m,t;
	cin >> n >> m >> t;
	if (t != 3) {
		return 0;
	}
	else {
		int fl = 0;
		for (int i = 1; i <= m; ++i) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			if (v != u + 1) {
				++fl;
				p[u]++;
				p[v]--;
			}
		}
		/*
		ll sum = 0;
		for (int i = 1; i < n; ++i) {
			sum += p[i];
			if (sum == 0) {
				fl += 1;
				break;
			}
		}
		*/
		cout << max(fl,1) << "\n"<< -1;
	}
}