#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 3000 + 5;
const int maxe = 5000 + 5;
int psz;
struct Edge {
  int v;
  Edge *next;
} pool[maxe], *e[maxn];
void add_edge(int u, int v) {
  Edge *i = pool + psz++;
  i->v = v, i->next = e[u];
  e[u] = i;
}
int n, m;
int dis[maxn][maxn];
int head, tail, que[maxn];
int s[maxn][3], t[maxn][3];
int ret;
vector<int> path;
void bfs(int s) {
  head = tail = dis[s][s] = 0, que[tail++] = s;
  while (head < tail) {
    int u = que[head++];
    for (Edge *i = e[u]; i; i = i->next) {
      int v = i->v;
      if (dis[s][v] == inf) dis[s][v] = dis[s][u] + 1, que[tail++] = v;
    }
  }
  dis[s][s] = inf;
}
void update(int s, int u, int v, int t) {
  if (s == -1 || t == -1 || s == t || s == v || u == t) return;
  int d = dis[s][u] + dis[u][v] + dis[v][t];
  if (d > ret) {
    ret = d;
    path.clear();
    path.push_back(s);
    path.push_back(u);
    path.push_back(v);
    path.push_back(t);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(--u, --v);
  }
  memset(dis, 0x3f, sizeof(dis));
  for (int u = 0; u < (n); ++u) bfs(u);
  memset(s, -1, sizeof(s));
  memset(t, -1, sizeof(t));
  for (int u = 0; u < (n); ++u)
    for (int v = 0; v < (n); ++v)
      if (dis[u][v] != inf) {
        if (s[v][0] == -1 || dis[u][v] > dis[s[v][0]][v])
          s[v][2] = s[v][1], s[v][1] = s[v][0], s[v][0] = u;
        else if (s[v][1] == -1 || dis[u][v] > dis[s[v][1]][v])
          s[v][2] = s[v][1], s[v][1] = u;
        else if (s[v][2] == -1 || dis[u][v] > dis[s[v][2]][v])
          s[v][2] = u;
        if (t[u][0] == -1 || dis[u][v] > dis[u][t[u][0]])
          t[u][2] = t[u][1], t[u][1] = t[u][0], t[u][0] = v;
        else if (t[u][1] == -1 || dis[u][v] > dis[u][t[u][1]])
          t[u][2] = t[u][1], t[u][1] = v;
        else if (t[u][2] == -1 || dis[u][v] > dis[u][t[u][2]])
          t[u][2] = v;
      }
  for (int u = 0; u < (n); ++u)
    for (int v = 0; v < (n); ++v)
      if (dis[u][v] != inf) {
        update(s[u][0], u, v, t[v][0]);
        update(s[u][0], u, v, t[v][1]);
        update(s[u][1], u, v, t[v][0]);
        update(s[u][0], u, v, t[v][2]);
        update(s[u][1], u, v, t[v][1]);
        update(s[u][2], u, v, t[v][0]);
      }
  for (__typeof(path.begin()) it = path.begin(); it != path.end(); ++it)
    printf("%d%c", *it + 1, " \n"[it == --path.end()]);
  return 0;
}
