#include <bits/stdc++.h>
using namespace std;
int parent(int a, int p[]) {
  if (p[a] == a) {
    return a;
  }
  return parent(p[a], p);
}
int main() {
  int n;
  cin >> n;
  int p[n + 1];
  for (int i = 0; i < n + 1; i++) {
    p[i] = i;
  }
  vector<pair<int, int> > bre, par;
  int count = 0;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    if (parent(b, p) == parent(a, p)) {
      count++;
      bre.push_back(make_pair(a, b));
    } else {
      p[parent(b, p)] = parent(a, p);
    }
  }
  for (int j = 2; j < n + 1; j++) {
    if (parent(j, p) != parent(1, p)) {
      par.push_back(make_pair(parent(1, p), parent(j, p)));
      p[parent(1, p)] = parent(j, p);
    }
  }
  cout << count << endl;
  for (auto i = bre.begin(), j = par.begin(); i != bre.end(); i++, j++) {
    cout << i->first << " " << i->second << " " << j->first << " " << j->second
         << " ";
    cout << endl;
  }
  return 0;
}
