#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
const int N = 10000 + 5;
vector<int> lk[N];
bool ban[N];
vector<pair<int, int> > ans;
set<pair<int, int> > ans_set;
void ans_push(int x, int y) {
  if (x > y) swap(x, y);
  pair<int, int> p = {x, y};
  if (ans_set.count(p)) return;
  ans_set.insert(p);
  ans.push_back(p);
}
int fa[N], sz[N], bsz[N];
vector<int> block[N];
void work(int rt) {
  vector<int> q;
  fa[rt] = 0;
  q.push_back(rt);
  for (int head = 0; head <= int(q.size()) - 1; ++head) {
    int x = q[head];
    sz[x] = 1;
    bsz[x] = 0;
    for (auto y : lk[x])
      if (!ban[y] && y != fa[x]) {
        fa[y] = x;
        q.push_back(y);
      }
  }
  int n = q.size();
  if (n <= 4) return;
  int g = min(n, int(sqrt(n) * 1.5));
  vector<int> big;
  for (int head = n - 1; head >= 1; --head) {
    int x = q[head];
    if (sz[x] >= g || bsz[x] > 1) {
      big.push_back(x);
      sz[x] = 0;
      bsz[x] = 1;
    }
    sz[fa[x]] += sz[x];
    bsz[fa[x]] += bsz[x];
  }
  big.push_back(rt);
  int m = big.size();
  for (int i = 0; i <= m - 1; ++i) {
    ban[big[i]] = 1;
    for (int j = i + 1; j <= m - 1; ++j) ans_push(big[i], big[j]);
  }
  for (int head = 1; head <= n - 1; ++head) {
    int x = q[head];
    if (!ban[x]) {
      int y = fa[x];
      while (!ban[y]) y = fa[y];
      ans_push(x, y);
      block[y].push_back(x);
    }
  }
  for (int head = 1; head <= n - 1; ++head) {
    int x = q[head];
    if (ban[x]) {
      int y = fa[x];
      while (!ban[y]) y = fa[y];
      for (auto z : block[y]) ans_push(x, z);
    }
  }
  for (auto x : q)
    if (!ban[x]) work(x);
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n - 1; ++i) {
    int x = read(), y = read();
    lk[x].push_back(y);
    lk[y].push_back(x);
    if (x > y) swap(x, y);
    ans_set.insert({x, y});
  }
  work(1);
  printf("%d\n", int(ans.size()));
  for (auto pr : ans) printf("%d %d\n", pr.first, pr.second);
}
