#include <iostream>
#include <vector>
#include <memory.h>
using namespace std;

int N, M;
vector<int> A[20000+1];
int memo[20000+1][5];

int solve(int n, int len)
{
    if (len == 5) {
        return n;
    }
    if (memo[n][len] >= 0) {
        return memo[n][len];
    }
    for (int i = 0; i < A[n].size(); i++) {
        if (solve(A[n][i], len+1) == 1) {
            return 1;
        }
    }
    memo[n][len] = 0;
    return 0;
}

int main()
{
    memset(memo, -1, sizeof(memo));

    cin >> N;
    cin >> M;
    while (M--) {
        int a, b;
        cin >> a;
        cin >> b;
        A[a].push_back(b);
        A[b].push_back(a);
    }
    cout << solve(1, 0) << endl;
}