from pprint import pprint # TODO - odstranit
def main():
  n = int(input())
  edges = {}
  edges_list = []
  edges_set = set()
  for i in range(n):
    xa, ya, xb, yb = map(int, input().split())
    edges.setdefault((xa, ya), []).append(((xb, yb), i))
    edges.setdefault((xb, yb), []).append(((xa, ya), i))
    edges_list.append((xa, ya, xb, yb))
    edges_set.add((xa, ya, xb, yb))
    edges_set.add((xb, yb, xa, ya))

  components = []
  used_state = [0] * n
  for i in range(len(used_state)):
    if used_state[i]:
      continue
    components.append(set())
    queue = []
    xa, ya, xb, yb = edges_list[i]
    queue.append((xa, ya))
    sett = components[-1]
    while queue:
      x, y = queue[-1]
      del queue[-1]
      sett.add((x, y))
      for (xn, yn), j in edges[(x, y)]:
        if (xn, yn) not in sett:
          sett.add((xn, yn))
          queue.append((xn, yn))
        used_state[j] = 1
  point_to_comp = {}
  for i, comp in enumerate(components):
    for point in comp:
      point_to_comp[point] = i
  #print('edges:') # TODO - odstranit
  #pprint(edges)
  #print()
  #print('components:')
  #pprint(components)
  #print()
  ##print('edges_set:')
  ##pprint(edges_set)
  ##print()
  #print(len(edges_set))
  #print('point_to_comp:') # TODO - odstranit
  #pprint(point_to_comp)
  #print()


# ret = 1:
  for comp in components:
    for x, y in comp:
      if ((x + 1, y) in comp and (x, y, x + 1, y) not in edges_set) \
        or ((x - 1, y) in comp and (x, y, x - 1, y) not in edges_set) \
        or ((x, y + 1) in comp and (x, y, x, y + 1) not in edges_set) \
        or ((x, y - 1) in comp and (x, y, x, y - 1) not in edges_set):
        print(1)
        return

# ret = 2 same component:
  for comp in components:
    for x, y in comp:
      if (x + 1, y + 1) in comp \
        or (x - 1, y + 1) in comp \
        or (x + 1, y - 1) in comp \
        or (x - 1, y - 1) in comp:
        print(2)
        return
# ret = 2 two components:
  for curr_num, comp in enumerate(components):
    nei_ctrs = [0] * len(components)
    for x, y in comp:
      for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        if (z := point_to_comp.get((x + dx, y + dy))) not in (curr_num, None):
          nei_ctrs[z] += 1
          if nei_ctrs[z] >= 2:
            print(2)
            return

  print(3)



# TODO - BACHA NA INDENTATION!!!!
main()
