#include <bits/stdc++.h>
using namespace std;
int p[1005];
int ff(int x) { return p[x] == x ? p[x] : p[x] = ff(p[x]); }
void uni(int u, int v) { p[ff(u)] = p[ff(v)]; }
int main() {
  int n, i, a, b;
  cin >> n;
  for (i = 1; i <= n; ++i) p[i] = i;
  vector<pair<int, int> > arr;
  vector<int> q;
  for (i = 1; i < n; ++i) {
    cin >> a >> b;
    if (ff(a) == ff(b))
      arr.push_back(make_pair(a, b));
    else
      uni(a, b);
  }
  for (i = 1; i <= n; ++i)
    if (ff(i) == i) q.push_back(i);
  cout << q.size() - 1 << endl;
  for (i = 1; i < (int)q.size(); ++i)
    printf("%d %d %d %d ", arr[i - 1].first, arr[i - 1].second, q[i - 1], q[i]);
}
