#include <bits/stdc++.h>
using namespace std;
int a, b, n, i, p[1001], sz[1001], cnt[1001];
vector<pair<int, int> > v2;
vector<int> v;
int find_p(int a) {
  if (p[a] == a) return a;
  return p[a] = find_p(p[a]);
}
void unionn(int a, int b) {
  int _a = a, _b = b;
  a = find_p(a);
  b = find_p(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    p[b] = a;
    sz[a] += sz[b];
  } else
    v2.push_back({_a, _b});
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) p[i] = i, sz[i] = 1;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    unionn(a, b);
  }
  cout << v2.size() << endl;
  for (i = 1; i <= n; i++) {
    p[i] = find_p(i);
    if (!cnt[p[i]]) {
      v.push_back(p[i]);
      cnt[p[i]] = 1;
    }
  }
  for (i = 0; i < v2.size(); i++) {
    cout << v2[i].first << ' ' << v2[i].second << ' ' << v[i] << ' ' << v[i + 1]
         << endl;
  }
}
