#include <bits/stdc++.h>
using namespace std;
int n;
int par[1005];
void init(int n) {
  for (int i = 1; i <= n; i++) par[i] = i;
}
int find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
void unite(int x, int y) { par[find(x)] = find(y); }
int main() {
  vector<int> p;
  vector<pair<int, int> > q;
  scanf("%d", &n);
  int a, b;
  init(n);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    if (find(a) == find(b))
      q.push_back(make_pair(a, b));
    else
      unite(a, b);
  }
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) p.push_back(i);
  }
  printf("%d\n", p.size() - 1);
  for (int i = 1; i < p.size(); i++) {
    printf("%d %d %d %d\n", q[i - 1].first, q[i - 1].second, p[i - 1], p[i]);
  }
  return 0;
}
