#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V>& x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T& x) {
  int f = 0;
  cerr << '{';
  for (auto& i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
int pct(int x) { return __builtin_popcount(x); }
int bits(int x) { return 31 - __builtin_clz(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
int fstTrue(function<bool(int)> first, int lo, int hi) {
  hi++;
  assert(lo <= hi);
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    first(mid) ? hi = mid : lo = mid + 1;
  }
  return lo;
}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const long long NINFLL = 0xc0c0c0c0c0c0c0c0;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
long long modInv(long long a) { return binpow(a, MOD - 2); }
bool sortcol(const vector<long long>& v1, const vector<long long>& v2) {
  return v1[1] < v2[1];
}
bool sortpair(const pair<int, int>& p1, const pair<int, int>& p2) {
  return p1.first < p2.first;
}
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<long long unsigned> distribution(0, 10);
const int mxN = 2e5;
int q = 1, n, k, a, b, sz[mxN], depth[mxN];
vector<int> adj[mxN];
vector<pair<int, int> > ans;
bool took;
int init_size_and_depth(int v, int p = -1) {
  if (p != -1) depth[v] = depth[p] + 1;
  sz[v] = 1;
  for (auto& x : adj[v]) {
    if (x != p) {
      sz[v] += init_size_and_depth(x, v);
    }
  }
  return sz[v];
}
int find_centroid(int v, int p, int n) {
  for (auto& x : adj[v]) {
    if (x != p && sz[x] > n / 2) {
      return find_centroid(x, v, n);
    }
  }
  return v;
}
vector<int> remove_edges(int v) {
  vector<int> neighbors;
  for (auto& x : adj[v]) neighbors.push_back(x);
  for (auto& x : neighbors) {
    adj[v].erase(find(adj[v].begin(), adj[v].end(), x));
    adj[x].erase(find(adj[x].begin(), adj[x].end(), v));
  }
  return neighbors;
}
void dfs(int c, int v, int p = -1, int dist = 0) {
  for (auto& x : adj[v]) {
    if (x != p) {
      if (!took && dist == 1)
        took = 1;
      else if (dist)
        ans.push_back({c, x});
      dfs(c, x, v, dist + 1);
    }
  }
}
void recurse(int x) {
  init_size_and_depth(x);
  if (sz[x] <= 2) return;
  int c = find_centroid(x, -1, sz[x]);
  took = 0;
  dfs(c, c);
  vector<int> neighbors = remove_edges(c);
  for (auto& i : neighbors) {
    recurse(i);
  }
}
void solve() {
  cin >> n >> k;
  for (int i = (0); i < (n - 1); i++) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  recurse(0);
  cout << ans.size() << "\n";
  for (auto& i : ans) cout << i.first + 1 << " " << i.second + 1 << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  while (q--) {
    solve();
  }
}
