#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, next;
} e[5010];
int n, m, cnt, head[3010], dis[3010][3010], res, ans[4];
bool vis[3010];
vector<pair<int, int> > A[3010], B[3010];
queue<int> Q;
inline void add(int u, int v) {
  cnt++;
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt;
}
inline void SPFA(int S) {
  memset(vis, 0, sizeof(vis));
  dis[S][S] = 0, vis[S] = 1;
  Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = 0;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (!(dis[S][u] + 1 < dis[S][v] || dis[S][v] == -1)) continue;
      dis[S][v] = dis[S][u] + 1;
      if (!vis[v]) Q.push(v), vis[v] = 1;
    }
  }
}
inline void init() {
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i <= n; i++) SPFA(i);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (i != j) {
        if (~dis[i][j]) A[i].push_back(make_pair(dis[i][j], j));
        if (~dis[j][i]) B[i].push_back(make_pair(dis[j][i], j));
      }
    sort(A[i].begin(), A[i].end());
    sort(B[i].begin(), B[i].end());
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j && ~dis[i][j]) {
        int C = B[i].size();
        int D = A[j].size();
        for (int p = C - 1; p >= 0 && p >= C - 3; p--)
          for (int q = D - 1; q >= 0 && q >= D - 3; q--) {
            int u = B[i][p].second;
            int v = A[j][q].second;
            if (u == v || u == i || u == j || v == i || v == j) continue;
            if (res < dis[u][i] + dis[i][j] + dis[j][v]) {
              res = dis[u][i] + dis[i][j] + dis[j][v];
              ans[0] = u, ans[1] = i, ans[2] = j, ans[3] = v;
            }
          }
      }
  for (int i = 0; i < 4; i++) printf("%d ", ans[i]);
  return 0;
}
