#include <bits/stdc++.h>
using namespace std;
const int MAX = 3010;
const int INF = (int)1E6 + 10;
int n, m, maxsum;
int c[MAX][MAX];
vector<int> a[MAX];
pair<int, int> fr[MAX][MAX], to[MAX][MAX];
vector<int> res;
void bfs(int x) {
  queue<int> qe;
  for (auto v : a[x]) qe.push(v);
  while (!qe.empty()) {
    int u = qe.front();
    qe.pop();
    for (auto v : a[u])
      if (c[x][v] == -INF) {
        c[x][v] = c[x][u] + 1;
        qe.push(v);
      }
  }
}
void check(int v1, int v2, int v3, int v4) {
  if (v1 == v2 || v1 == v3 || v1 == v4 || v2 == v4 || v3 == v4) return;
  int sum = c[v1][v2] + c[v2][v3] + c[v3][v4];
  if (sum > maxsum) {
    maxsum = sum;
    res.resize(0);
    res.push_back(v1);
    res.push_back(v2);
    res.push_back(v3);
    res.push_back(v4);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j) c[i][j] = -INF;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    if (c[x][y] == -INF) {
      c[x][y] = 1;
      a[x].push_back(y);
    }
  }
  for (int i = 0; i < n; i++) bfs(i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      fr[i][j] = make_pair(c[i][j], j);
      to[i][j] = make_pair(c[j][i], j);
    }
  for (int i = 0; i < n; i++) {
    sort(fr[i], fr[i] + n, greater<pair<int, int> >());
    sort(to[i], to[i] + n, greater<pair<int, int> >());
    for (int j = n; j < 6; j++) {
      fr[i][j] = make_pair(-INF, n);
      to[i][j] = make_pair(-INF, n);
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (c[j][i] > 0) {
        for (int p = 0; p < 3; p++)
          for (int q = 0; q < 3; q++)
            check(to[j][p].second, j, i, fr[i][q].second);
      }
  for (auto v : res) printf("%d ", v + 1);
}
