#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops", \
                     "omit-frame-pointer", "inline")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC option("arch=native", "no-zero-upper")
using namespace std;
const long long oo = (long long)(1e9);
vector<int> g[(long long)(3e5 + 5)], nodes;
bool mk1[(long long)(3e5 + 5)], mk2[(long long)(3e5 + 5)];
int sons[(long long)(3e5 + 5)][2];
vector<pair<long long, long long> > res;
void dfs1(int u) {
  mk1[u] = 1;
  sons[u][0] = 1;
  nodes.push_back(u);
  for (auto v : g[u])
    if (!mk1[v] && !mk2[v]) {
      dfs1(v);
      sons[u][0] += sons[v][0];
      sons[u][1] = max(sons[v][0], sons[u][1]);
    }
}
void dfs2(int u) {
  mk1[u] = 1;
  nodes.push_back(u);
  for (auto v : g[u])
    if (!mk1[v] && !mk2[v]) dfs2(v);
}
void solve(int u) {
  dfs1(u);
  if (nodes.size() <= 2) {
    for (auto v : nodes) {
      sons[v][0] = sons[v][1] = 0;
      mk2[v] = 1;
    }
    nodes.clear();
    return;
  }
  int cent1 = -1, cant = nodes.size() / 3;
  for (auto v : nodes) {
    if (cent1 == -1 && sons[v][0] >= cant && sons[v][1] <= cant) cent1 = v;
    mk1[v] = sons[v][0] = sons[v][1] = 0;
  }
  nodes.clear();
  mk2[cent1] = 1;
  if (cent1 == u) {
    for (auto v : g[cent1]) {
      if (mk2[v]) continue;
      dfs2(v);
      for (auto y : nodes) {
        res.push_back(pair<long long, long long>(y, cent1));
        mk1[y] = 0;
      }
      nodes.clear();
    }
    for (auto v : g[cent1])
      if (!mk2[v]) solve(v);
    return;
  }
  dfs1(u);
  int cent2 = -1;
  cant = nodes.size() / 2;
  for (auto v : nodes) {
    if (cent2 == -1 && sons[v][0] >= cant && sons[v][1] <= cant) cent2 = v;
    mk1[v] = sons[v][0] = sons[v][1] = 0;
  }
  nodes.clear();
  mk2[cent2] = 1;
  for (auto v : g[cent1]) {
    if (mk2[v]) continue;
    dfs2(v);
    for (auto y : nodes) {
      res.push_back(pair<long long, long long>(y, cent1));
      mk1[y] = 0;
    }
    nodes.clear();
  }
  for (auto v : g[cent2]) {
    if (mk2[v]) continue;
    dfs2(v);
    for (auto y : nodes) {
      res.push_back(pair<long long, long long>(y, cent2));
      mk1[y] = 0;
    }
    nodes.clear();
  }
  res.push_back(pair<long long, long long>(cent1, cent2));
  for (auto v : g[cent1])
    if (!mk2[v]) solve(v);
  for (auto v : g[cent2])
    if (!mk2[v]) solve(v);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  map<pair<long long, long long>, bool> there;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
    there[pair<long long, long long>(u, v)] =
        there[pair<long long, long long>(v, u)] = 1;
  }
  solve(0);
  vector<pair<long long, long long> > tr;
  for (auto y : res) {
    if (there[y]) continue;
    tr.push_back(y);
  }
  cout << (tr.size()) << '\n';
  for (auto y : tr) cout << y.first + 1 << ' ' << y.second + 1 << '\n';
  return 0;
}
