#include <bits/stdc++.h>
using namespace std;
int par[1001], n;
deque<pair<int, int> > Bridges;
deque<int> Khop;
bool dau[1001];
void setup() {
  for (int i = 1; i <= n; ++i) {
    par[i] = i;
    dau[i] = false;
  }
  Bridges.clear();
  Khop.clear();
}
int root(int x) {
  while (x != par[x]) {
    x = par[x];
  }
  return x;
}
void xuly(int i, int j) {
  int tami = i;
  int tamj = j;
  i = root(i);
  j = root(j);
  if (i != j) {
    par[i] = j;
  } else {
    Bridges.push_back(make_pair(tami, tamj));
  }
}
void nhap() {
  int u, v;
  scanf("%d", &n);
  setup();
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    xuly(u, v);
  }
}
void sol() {
  for (int i = 1; i <= n; ++i) {
    par[i] = root(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (dau[par[i]] == false) {
      dau[par[i]] = true;
      Khop.push_back(par[i]);
    }
  }
  printf("%d\n", (int)Khop.size() - 1);
  while (Khop.size() >= 2) {
    printf("%d %d %d %d\n", Bridges[0].first, Bridges[0].second, Khop[0],
           Khop[1]);
    Bridges.pop_front();
    Khop.pop_front();
  }
}
int main() {
  nhap();
  sol();
  return 0;
}
