#include <bits/stdc++.h>
using namespace std;
const int C = 100001;
vector<vector<int> > tr(C);
int ij[C], a, b, n, ss = 0;
int check[C], d[C], rd[2][C], pd[C], bel[C];
int pom[C], pom2[C];
void Sebasort(int tab[], int tab2[], int l, int r) {
  int lim = 2, limi = l + 1, limj = l + 2, j = limi, i = l, k = l;
  while (lim / 2 <= r - l + 1) {
    while (i <= r) {
      if (limj > r) limj = r + 1;
      if ((j < limj && tab[j] < tab[i]) || i >= limi)
        pom[k] = tab[j], pom2[k] = tab2[j], j++;
      else
        pom[k] = tab[i], pom2[k] = tab2[i], i++;
      k++;
      if (i == limi && j == limj) limi += lim, limj += lim, i = j, j = limi;
    }
    for (i = l; i <= r; i++) tab[i] = pom[i], tab2[i] = pom2[i];
    lim *= 2, limi = l + lim / 2, limj = l + lim, j = limi, i = k = l;
  }
}
int s[C], is = 0, par[C], ji[C];
void proc_tree(int a, int n, vector<vector<int> > &tab, int ij[]) {
  s[0] = a, is = 1, check[a] = 1;
  int b, ad = 0, ard = a, i = 0;
  while (is > 0) {
    a = s[is - 1];
    if (ji[a] > 0 && tab[a][ji[a] - 1] == par[a]) ji[a]--;
    if (ji[a] > 0)
      b = s[is] = tab[a][ji[a] - 1], check[b] = 1, par[b] = a, is++, ji[a]--;
    else {
      if (rd[0][par[a]] < rd[0][a] + 1)
        rd[1][par[a]] = rd[0][par[a]], rd[0][par[a]] = rd[0][a] + 1,
        bel[par[a]] = a;
      else if (rd[1][par[a]] < rd[0][a] + 1)
        rd[1][par[a]] = rd[0][a] + 1;
      if (rd[0][a] + rd[1][a] > ad) ad = rd[0][a] + rd[1][a], ard = a;
      is--;
    }
  }
  while (ad < 2 * rd[0][ard]) ard = bel[ard];
  d[ss] = ad, pd[ss] = ard;
}
int fl(int a) {
  if (a % 2 == 0) return a / 2;
  return a / 2 + 1;
}
int main() {
  int wynn, i, m;
  scanf("%d %d", &n, &m);
  for (int z = 0; z < m; z++)
    scanf("%d %d", &a, &b), tr[a].push_back(b), tr[b].push_back(a), ij[a]++,
        ij[b]++;
  for (int z = 1; z <= n; z++) ji[z] = ij[z], par[z] = 0;
  for (i = 1; i <= n; i++)
    if (check[i] == 0) proc_tree(i, n, tr, ij), ss++;
  Sebasort(d, pd, 0, ss - 1);
  if (ss > 2) {
    wynn = max(fl(d[ss - 1]) + fl(d[ss - 2]) + 1, d[ss - 1]);
    wynn = max(wynn, fl(d[ss - 2]) + fl(d[ss - 3]) + 2);
  } else if (ss == 2)
    wynn = max(fl(d[ss - 1]) + fl(d[ss - 2]) + 1, d[ss - 1]);
  else
    wynn = d[ss - 1];
  printf("%d\n", wynn);
  for (i = 0; i < ss - 1; i++) printf("%d %d\n", pd[ss - 1], pd[i]);
  return 0;
}
