#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int M = 5005;
struct edge {
  int next, to;
} e[M];
int n, m, g[N][N], p[N][4], f[N][4];
int p2[N][4], f2[N][4];
bool vis[N], G[N][N];
int head[N], cnt, a, b, c, d;
void bfs(int s) {
  queue<int> q;
  memset(vis, false, sizeof(vis));
  q.push(s);
  vis[s] = true;
  int h, i;
  while (!q.empty()) {
    h = q.front();
    q.pop();
    for (i = head[h]; i; i = e[i].next)
      if (!vis[e[i].to]) {
        g[s][e[i].to] = g[s][h] + 1;
        q.push(e[i].to);
        vis[e[i].to] = true;
      }
  }
}
void link(int u, int v) {
  ++cnt;
  e[cnt].next = head[u];
  e[cnt].to = v;
  head[u] = cnt;
  G[u][v] = true;
}
int main() {
  scanf("%d%d", &n, &m);
  int i, j, k, l, r;
  int x, y, s, h, ans = 0;
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    if (G[x][y] || x == y) continue;
    link(x, y);
    if (i == 1) l = x, r = y;
  }
  for (i = 1; i <= n; ++i) bfs(i);
  for (s = 1; s <= n; ++s)
    for (h = 1; h <= n; ++h)
      if (h != s) {
        for (j = 1; j <= 3; ++j)
          if (g[s][h] > f[s][j]) break;
        if (j <= 3) {
          k = j + 1;
          for (j = 3; j >= k; --j) {
            f[s][j] = f[s][j - 1];
            p[s][j] = p[s][j - 1];
          }
          f[s][k - 1] = g[s][h];
          p[s][k - 1] = h;
        }
      }
  for (s = 1; s <= n; ++s)
    for (h = 1; h <= n; ++h)
      if (h != s) {
        for (j = 1; j <= 3; ++j)
          if (g[h][s] > f2[s][j]) break;
        if (j <= 3) {
          k = j + 1;
          for (j = 3; j >= k; --j) {
            f2[s][j] = f2[s][j - 1];
            p2[s][j] = p2[s][j - 1];
          }
          f2[s][k - 1] = g[h][s];
          p2[s][k - 1] = h;
        }
      }
  for (x = 1; x <= n; ++x)
    for (y = 1; y <= n; ++y)
      for (i = 1; i <= 3; ++i)
        for (j = 1; j <= 3; ++j)
          if (g[x][y] && x != y && p2[x][i] != p[y][j] && p2[x][i] != y &&
              p[y][j] != x && p[y][j] && p2[x][i]) {
            if (f2[x][i] + g[x][y] + f[y][j] > ans) {
              ans = f2[x][i] + g[x][y] + f[y][j];
              a = p2[x][i];
              b = x;
              c = y;
              d = p[y][j];
            }
          }
  printf("%d %d %d %d", a, b, c, d);
  return 0;
}
