#include <bits/stdc++.h>
using namespace std;
int n, m, parent[1009], x, y, kkomp;
vector<pair<int, int> > forDel;
set<int> komp;
int find_set(int v) {
  if (parent[v] == v) return v;
  return parent[v] = find_set(parent[v]);
}
void union_set(int v, int u) {
  u = find_set(u);
  v = find_set(v);
  if (rand() % 2 == 0)
    parent[v] = u;
  else
    parent[u] = v;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) parent[i] = i;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    if (find_set(x) == find_set(y))
      forDel.push_back(make_pair(x, y));
    else
      union_set(x, y);
  }
  for (int i = 1; i <= n; i++) komp.insert(find_set(i));
  cout << komp.size() - 1 << endl;
  kkomp = komp.size();
  if (komp.size() == 1) return 0;
  for (int i = 0; i < forDel.size(); i++) {
    if (komp.size() == 0) break;
    cout << forDel[i].first << ' ' << forDel[i].second << ' ' << *komp.begin()
         << ' ';
    komp.erase(*komp.begin());
    cout << *komp.begin() << endl;
  }
  return 0;
}
