#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
int dis[maxn][maxn], s, vis[maxn], id[maxn][maxn], q[maxn], head, tail, n, m;
int dis2[maxn][maxn], id2[maxn][maxn], ans1, ans2, ans3, ans4, mx;
vector<int> g[maxn];
vector<int> h[maxn];
void bfs(int p) {
  dis[p][p] = 0;
  vis[p] = 1;
  q[head = tail = 1] = p;
  while (head <= tail) {
    int x = q[head];
    head++;
    for (int i = 0; i < g[x].size(); i++) {
      int v = g[x][i];
      if (!vis[v]) {
        vis[v] = 1;
        dis[p][v] = dis[p][x] + 1;
        q[++tail] = v;
      }
    }
  }
}
void bfs2(int p) {
  dis2[p][p] = 0;
  vis[p] = 1;
  q[head = tail = 1] = p;
  while (head <= tail) {
    int x = q[head];
    head++;
    for (int i = 0; i < h[x].size(); i++) {
      int v = h[x][i];
      if (!vis[v]) {
        vis[v] = 1;
        dis2[p][v] = dis2[p][x] + 1;
        q[++tail] = v;
      }
    }
  }
}
int cmp(int a, int b) { return dis[s][a] > dis[s][b]; }
int cmp2(int a, int b) { return dis2[s][a] > dis2[s][b]; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    h[y].push_back(x);
  }
  for (s = 1; s <= n; s++) {
    memset(vis, 0, sizeof(vis));
    bfs(s);
    for (int j = 1; j <= n; j++) id[s][j] = j;
    sort(id[s] + 1, id[s] + n + 1, cmp);
  }
  for (s = 1; s <= n; s++) {
    memset(vis, 0, sizeof(vis));
    bfs2(s);
    for (int j = 1; j <= n; j++) id2[s][j] = j;
    sort(id2[s] + 1, id2[s] + n + 1, cmp2);
  }
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= n; y++)
      if (x != y && dis[x][y])
        for (int i = 1; i <= 4; i++)
          if (id2[x][i] != y && id2[x][i] != x && dis2[x][id2[x][i]])
            for (int j = 1; j <= 4; j++)
              if (dis[y][id[y][j]] && id[y][j] != id2[x][i] && id[y][j] != x &&
                  id[y][j] != y) {
                int val = dis[x][y] + dis2[x][id2[x][i]] + dis[y][id[y][j]];
                if (val > mx) {
                  mx = val;
                  ans1 = id2[x][i];
                  ans2 = x;
                  ans3 = y;
                  ans4 = id[y][j];
                }
              }
  printf("%d %d %d %d", ans1, ans2, ans3, ans4);
}
