#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
typedef vector<int> vi;

const int maxn = 1e5;
vi G[maxn], leaves;

void dfs(int u, int v)
{
	for (int w : G[v]) if (w != u) dfs(v, w);
	if (G[v].size() == 1) leaves.pb(v);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, p;
	cin >> n >> p;
	vi deg(n, 0);
	REP(i, n - 1) {
		int x, y;
		cin >> x >> y;
		G[x].pb(y);
		G[y].pb(x);
	}

	dfs(-1, 0);

	int m = leaves.size(), r = (m+1)/2;
	printf("%d\n", r);
	REP(i, r) printf("%d %d\n", leaves[i], leaves[i+m/2]);
	return 0;
}
