#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010, inf = 0x7ffffff;
int n, m, head1[maxn], to1[maxn], nextt1[maxn], tot1 = 1;
int head2[maxn], to2[maxn], nextt2[maxn], tot2 = 1;
int ans1[maxn][3], pos1[maxn][3], d1[3010][3010], d2[3010][3010], pos2[maxn][3];
int vis1[maxn], vis2[maxn], a[3010][3010], ans[4], maxx, ans2[maxn][3];
void add1(int x, int y) {
  to1[tot1] = y;
  nextt1[tot1] = head1[x];
  head1[x] = tot1++;
}
void add2(int x, int y) {
  to2[tot2] = y;
  nextt2[tot2] = head2[x];
  head2[x] = tot2++;
}
void push1(int d, int x, int y) {
  if (d > ans1[x][0]) {
    ans1[x][2] = ans1[x][1];
    pos1[x][2] = pos1[x][1];
    ans1[x][1] = ans1[x][0];
    pos1[x][1] = pos1[x][0];
    ans1[x][0] = d;
    pos1[x][0] = y;
  } else if (d > ans1[x][1]) {
    ans1[x][2] = ans1[x][1];
    pos1[x][2] = pos1[x][1];
    ans1[x][1] = d;
    pos1[x][1] = y;
  } else if (d > ans1[x][2]) {
    ans1[x][2] = d;
    pos1[x][2] = y;
  }
}
void push2(int d, int x, int y) {
  if (d > ans2[x][0]) {
    ans2[x][2] = ans2[x][1];
    pos2[x][2] = pos2[x][1];
    ans2[x][1] = ans2[x][0];
    pos2[x][1] = pos2[x][0];
    ans2[x][0] = d;
    pos2[x][0] = y;
  } else if (d > ans2[x][1]) {
    ans2[x][2] = ans2[x][1];
    pos2[x][2] = pos2[x][1];
    ans2[x][1] = d;
    pos2[x][1] = y;
  } else if (d > ans2[x][2]) {
    ans2[x][2] = d;
    pos2[x][2] = y;
  }
}
void bfs(int x) {
  for (int i = 1; i <= n; i++) d1[x][i] = d2[x][i] = inf;
  memset(vis1, 0, sizeof(vis1));
  memset(vis2, 0, sizeof(vis2));
  queue<int> q;
  q.push(x);
  vis1[x] = 1;
  d1[x][x] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis1[u] = 0;
    for (int i = head1[u]; i; i = nextt1[i]) {
      int v = to1[i];
      if (d1[x][v] > d1[x][u] + 1) {
        d1[x][v] = d1[x][u] + 1;
        if (!vis1[v]) {
          vis1[v] = 1;
          q.push(v);
        }
      }
    }
  }
  while (!q.empty()) q.pop();
  q.push(x);
  vis2[x] = 1;
  d2[x][x] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis2[u] = 0;
    for (int i = head2[u]; i; i = nextt2[i]) {
      int v = to2[i];
      if (d2[x][v] > d2[x][u] + 1) {
        d2[x][v] = d2[x][u] + 1;
        if (!vis2[v]) {
          vis2[v] = 1;
          q.push(v);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (d1[x][i] != inf) push1(d1[x][i], x, i);
    if (d2[x][i] != inf) push2(d2[x][i], x, i);
  }
}
int check(int x, int y, int k1, int k2) {
  int a1 = pos2[x][k1];
  int a2 = pos1[y][k2];
  if (x == 0 || y == 0 || a1 == 0 || a2 == 0) return -1;
  if (a1 != a2 && a2 != x && x != y && y != a1)
    return ans2[x][k1] + ans1[y][k2] + d1[x][y];
  return -1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x][y] = 1;
    add1(x, y);
    add2(y, x);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || d1[i][j] >= inf) continue;
      for (int k1 = 0; k1 < 3; k1++) {
        for (int k2 = 0; k2 < 3; k2++) {
          int temp = check(i, j, k1, k2);
          if (temp > maxx) {
            ans[0] = pos2[i][k1];
            ans[1] = i;
            ans[2] = j;
            ans[3] = pos1[j][k2];
            maxx = temp;
          }
        }
      }
    }
  }
  for (int i = 0; i <= 3; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
