/* coder: ACboy date: 2010-3-19 result: AC description: UVa 539 The Settlers of Catan */ #include <iostream> using namespace std; int edges[30][30]; int vis[30][30]; int v[30]; int c; int begin; int end; int ans; // 图的回溯 void dfs(int pos, int n) { if (pos - 1 > ans) { ans = pos - 1; } for (int i = 0; i < n; i++) { if (edges[v[pos - 1]][i] && edges[i][v[pos - 1]] && !vis[i][v[pos - 1]] && !vis[v[pos - 1]][i]) { v[pos] = i; vis[i][v[pos - 1]] = 1; vis[v[pos - 1]][i] = 1; dfs(pos + 1, n); vis[i][v[pos - 1]] = 0; vis[v[pos - 1]][i] = 0; } } } int main() { int n, m; #ifndef ONLINE_JUDGE freopen("539.txt", "r", stdin); #endif while (cin >> n >> m) { if (n == m && n == 0) break; int i; memset(edges, 0, sizeof(edges)); for (i = 0; i < m; i++) { int a, b; cin >> a >> b; edges[a][b] = 1; edges[b][a] = 1; } ans = 0; // 以每个节点为起点回溯n遍 for (i = 0; i < n; i++) { memset(vis, 0, sizeof(vis)); v[0] = i; dfs(1, n); } cout << ans << endl; } return 0; }