#include <bits/stdc++.h>
using namespace std;
int par[1001];
int find(int a) {
  if (par[a] == a) return a;
  return par[a] = find(par[a]);
}
void unio(int a, int b) {
  int pa = find(a);
  int pb = find(b);
  if (pa == pb) return;
  par[pb] = pa;
}
void make(int v) { par[v] = v; }
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > vp;
  vector<int> unq;
  for (int i = 1; i <= n; i++) make(i);
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    if (find(a) == find(b))
      vp.push_back({a, b});
    else {
      unio(a, b);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (find(unq.begin(), unq.end(), find(i)) == unq.end())
      unq.push_back(par[i]);
  }
  cout << unq.size() - 1 << "\n";
  for (int i = 0; i < unq.size() - 1; i++)
    cout << vp[i].first << " " << vp[i].second << " " << unq[i] << " "
         << unq[i + 1] << "\n";
  return 0;
}
