#include <bits/stdc++.h>
using namespace std;
int dis[3030][3030];
struct EDGE {
  int to, next;
} e[5050];
queue<int> q;
int n, m, head[3030], tot;
bool mark[3030];
void dij(int t) {
  for (int i = 1; i <= n; i++) {
    dis[t][i] = -1;
    mark[i] = false;
  }
  mark[t] = true;
  dis[t][t] = 0;
  while (!q.empty()) q.pop();
  q.push(t);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i >= 0; i = e[i].next) {
      int v = e[i].to;
      if (mark[v]) continue;
      if (dis[t][v] == -1) {
        dis[t][v] = dis[t][u] + 1;
        mark[v] = true;
        q.push(v);
      }
    }
  }
}
struct node {
  int bh, val;
  node() {}
  node(const int &bh, const int &val) : bh(bh), val(val) {}
  bool operator<(const node &b) const { return val > b.val; }
} Max[3030][4], Mtx[3030][4];
int ans, ans_print[4];
int main() {
  scanf("%d%d", &n, &m);
  tot = 0;
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[tot].to = v;
    e[tot].next = head[u];
    head[u] = tot++;
  }
  for (int i = 1; i <= n; i++) {
    dij(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      Max[i][j].bh = 0;
      Max[i][j].val = -2;
      Mtx[i][j].bh = 0;
      Mtx[i][j].val = -2;
    }
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      Max[i][3].bh = j;
      Max[i][3].val = dis[i][j];
      Mtx[i][3].bh = j;
      Mtx[i][3].val = dis[j][i];
      sort(Max[i], Max[i] + 4);
      sort(Mtx[i], Mtx[i] + 4);
    }
  }
  ans = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      if (dis[i][j] == -1) continue;
      for (int l = 0; l < 3; l++) {
        if (Mtx[i][l].val <= 0) break;
        if (Mtx[i][l].bh == i || Mtx[i][l].bh == j) continue;
        for (int o = 0; o < 3; o++) {
          if (Max[j][o].val <= 0) break;
          if (Max[j][o].bh == i || Max[j][o].bh == j ||
              Max[j][o].bh == Mtx[i][l].bh)
            continue;
          if (Mtx[i][l].val + dis[i][j] + Max[j][o].val > ans) {
            ans = Mtx[i][l].val + dis[i][j] + Max[j][o].val;
            ans_print[0] = Mtx[i][l].bh;
            ans_print[1] = i;
            ans_print[2] = j;
            ans_print[3] = Max[j][o].bh;
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    printf("%d", ans_print[i]);
    if (i == 3)
      printf("\n");
    else
      printf(" ");
  }
}
