PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000013. Sáu bậc quan hệ (Degrees of Separation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sáu bậc quan hệ (Degrees of Separation)

Degrees of Separation

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Undirected relationships form an unweighted graph. Find the largest shortest number of hops among all pairs; print DISCONNECTED if any pair cannot be connected.

Input

n,mn,m followed by mm pairs of single-token names.

Output

Print the network diameter or DISCONNECTED.

Subtasks

  • Subtask 1 (40 points): n≤12n\le 12; 2≤n≤502\le n\le 50; 1≤m≤12251\le m\le 1225.
  • Subtask 2 (60 points): 2≤n≤502\le n\le 50; 1≤m≤12251\le m\le 1225.

Examples

Input

3 2
Ana Ben
Ben Cam

Output

2

Explanation

Ana and Cam are separated by two relationships via Ben, so the network diameter is 22.