#include <bits/stdc++.h>
using namespace std;
int n, m, l[5001][4], r[5001][4], dis[5001][5001], t, linkk[5001], q[5001],
    tail, max1, maxa, maxb, maxc, maxd;
bool vis[5001];
struct hzy {
  int next, val;
} e[5001];
void ling(int x, int y) {
  e[++t].val = y;
  e[t].next = linkk[x];
  linkk[x] = t;
}
void bfs(int x) {
  memset(vis, 0, sizeof(vis));
  vis[x] = 1;
  q[1] = x;
  tail = 1;
  dis[x][x] = 0;
  for (int i = 1; i <= tail; i++) {
    int now = q[i];
    for (int j = linkk[now]; j; j = e[j].next) {
      int y = e[j].val;
      if (vis[y] == 0) {
        dis[x][y] = dis[x][now] + 1;
        vis[y] = 1;
        q[++tail] = y;
      }
    }
  }
}
int main() {
  memset(dis, -10, sizeof(dis));
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; i++) {
    cin >> x >> y;
    ling(x, y);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  for (int i = 1; i <= n; i++) {
    l[i][0] = l[i][1] = l[i][2] = i;
    for (int j = 1; j <= n; j++)
      if (dis[j][i] > dis[l[i][0]][i]) l[i][0] = j;
    for (int j = 1; j <= n; j++)
      if (dis[j][i] > dis[l[i][1]][i] && j != l[i][0]) l[i][1] = j;
    for (int j = 1; j <= n; j++)
      if (dis[j][i] > dis[l[i][2]][i] && j != l[i][0] && j != l[i][1])
        l[i][2] = j;
  }
  for (int i = 1; i <= n; i++) {
    r[i][0] = r[i][1] = r[i][2] = i;
    for (int j = 1; j <= n; j++)
      if (dis[i][j] > dis[i][r[i][0]]) r[i][0] = j;
    for (int j = 1; j <= n; j++)
      if (dis[i][j] > dis[i][r[i][1]] && j != r[i][0]) r[i][1] = j;
    for (int j = 1; j <= n; j++)
      if (dis[i][j] > dis[i][r[i][2]] && j != r[i][0] && j != r[i][1])
        r[i][2] = j;
  }
  for (int b = 1; b <= n; b++) {
    for (int c = 1; c <= n; c++) {
      if (b != c) {
        for (int i = 0; i < 4; i++) {
          int a = l[b][i];
          if (a != b && a != c) {
            for (int j = 0; j < 4; j++) {
              int d = r[c][j];
              if (a != d && b != d && c != d) {
                if (dis[a][b] + dis[b][c] + dis[c][d] > max1) {
                  max1 = dis[a][b] + dis[b][c] + dis[c][d];
                  maxa = a;
                  maxb = b;
                  maxc = c;
                  maxd = d;
                }
              }
            }
          }
        }
      }
    }
  }
  cout << maxa << ' ' << maxb << ' ' << maxc << ' ' << maxd;
  return 0;
}
