#include <bits/stdc++.h>
using namespace std;
int parent[10005], s[10005];
vector<pair<int, int> > v;
void make_set(int u) {
  parent[u] = u;
  s[u] = 1;
}
int find_set(int u) {
  if (parent[u] == u) return u;
  return parent[u] = find_set(parent[u]);
}
void union_set(int u1, int v1) {
  int a = find_set(u1);
  int b = find_set(v1);
  if (a != b) {
    parent[b] = a;
  } else {
    v.push_back(make_pair(u1, v1));
  }
}
int main() {
  long long n;
  cin >> n;
  long long u1, v1;
  for (int i = 1; i <= n; i++) make_set(i);
  for (int i = 0; i < n - 1; i++) {
    cin >> u1 >> v1;
    union_set(u1, v1);
  }
  vector<int> ch;
  for (int i = 1; i <= n; i++) {
    if (find_set(i) == i) ch.push_back(i);
  }
  cout << ch.size() - 1 << endl;
  for (int i = 1; i < ch.size(); i++) {
    cout << v[i - 1].first << " " << v[i - 1].second << " " << ch[i - 1] << " "
         << ch[i] << "\n";
  }
}
