#include <bits/stdc++.h>
const int MAXN = 3005;
const int MAXM = 5005;
int n, m;
struct edge {
  edge *next;
  int y;
};
edge *first[MAXN], e[MAXM], *etot = e;
inline void addedge(int x, int y) {
  *++etot = (edge){first[x], y};
  first[x] = etot;
}
int dist[MAXN][MAXN];
void bfs(int S) {
  int *dist = ::dist[S];
  static int l[MAXN];
  int s = 0, t = 1;
  l[1] = S;
  static bool visit[MAXN];
  memset(visit, 0, sizeof(visit));
  memset(dist, 0x3f, MAXN * sizeof(int));
  dist[S] = 0;
  visit[S] = 1;
  while (s < t) {
    int x = l[++s];
    for (edge *e = first[x]; e; e = e->next) {
      int y = e->y;
      if (!visit[y]) {
        visit[y] = 1;
        l[++t] = y;
        dist[y] = dist[x] + 1;
      }
    }
  }
}
int idr[MAXN][3];
int idl[MAXN][3];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      int tmp = 0, x = 0;
      for (int k = 1; k <= n; k++) {
        if (k != i && k != idr[i][0] && k != idr[i][1] && k != idr[i][2] &&
            dist[i][k] < 0x3f3f3f3f && dist[i][k] > tmp) {
          tmp = dist[i][k], x = k;
        }
      }
      idr[i][j] = x;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      int tmp = 0, x = 0;
      for (int k = 1; k <= n; k++) {
        if (k != i && k != idl[i][0] && k != idl[i][1] && k != idl[i][2] &&
            dist[k][i] < 0x3f3f3f3f && dist[k][i] > tmp) {
          tmp = dist[k][i], x = k;
        }
      }
      idl[i][j] = x;
    }
  }
  int ans = 0, a = 0, b = 0, c = 0, d = 0;
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= n; y++) {
      if (x == y || dist[x][y] == 0x3f3f3f3f) continue;
      for (int i = 0; i < 3; i++) {
        int l = idl[x][i];
        if (l == x || l == y || l == 0) continue;
        for (int j = 0; j < 3; j++) {
          int r = idr[y][j];
          if (r == x || r == y || r == l || r == 0) continue;
          int tmp = dist[l][x] + dist[x][y] + dist[y][r];
          if (tmp > ans) ans = tmp, a = l, b = x, c = y, d = r;
        }
      }
    }
  }
  printf("%d %d %d %d\n", a, b, c, d);
}
