#include <bits/stdc++.h>
using namespace std;
int parent[3001];
int ranke[3001];
int cycle[3001];
vector<int> lol;
vector<pair<int, int> > bad;
vector<vector<int> > spisok;
set<int> komponents;
void make_new(int v) {
  parent[v] = v;
  ranke[v] = 0;
}
int find_set(int v) {
  if (parent[v] == v)
    return v;
  else {
    return parent[v] = find_set(parent[v]);
  }
}
void set_union(int a, int b) {
  pair<int, int> c = make_pair(a, b);
  a = find_set(a);
  b = find_set(b);
  if (a == b) bad.push_back(c);
  if (a != b) {
    if (ranke[a] < ranke[b]) swap(a, b);
    parent[a] = b;
    komponents.erase(a);
    if (ranke[a] == ranke[b]) ranke[b]++;
  }
}
int main() {
  memset(cycle, 0, sizeof(cycle));
  int n, i, j;
  cin >> n;
  spisok.resize(n + 1, lol);
  for (i = 0; i < n; i++) {
    komponents.insert(i + 1);
    make_new(i + 1);
  }
  for (i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    set_union(a, b);
    spisok[a].push_back(b);
    spisok[b].push_back(a);
  }
  int tre;
  set<int>::iterator it, it2;
  it = komponents.begin();
  it2 = it;
  j = 0;
  cout << komponents.size() - 1 << endl;
  for (i = 0; i < komponents.size() - 1; i++) {
    it2++;
    cout << bad[j].first << " " << bad[j].second << " " << *it << " " << *it2;
    cout << endl;
    j++;
  }
  return 0;
}
