#include <bits/stdc++.h>
using namespace std;
vector<int> g[3010], gr[3010];
pair<int, int> d[3010][3010], dr[3010][3010];
pair<int, int> e[3010];
queue<int> q;
pair<int, int> ge[3010][5], gre[3010][5];
void bfs(int x, vector<int> g[], pair<int, int> d[]) {
  int y = x;
  q.push(x);
  int i;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (i = 0; i < g[x].size(); i++)
      if (!d[g[x][i]].first && g[x][i] != y) {
        d[g[x][i]].first = d[x].first + 1;
        q.push(g[x][i]);
      }
  }
}
int main() {
  int n, m, i, j, l, p, x, y, z, t;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    gr[y].push_back(x);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      d[i][j].first = 0;
      d[i][j].second = j;
    }
    bfs(i, g, d[i]);
    d[i][i].first = -1;
    memcpy(e, d[i], sizeof d[i]);
    sort(e + 1, e + n + 1);
    for (j = n; j >= n - 2; j--) ge[i][n - j] = e[j];
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dr[i][j].first = 0;
      dr[i][j].second = j;
    }
    bfs(i, gr, dr[i]);
    dr[i][i].first = -1;
    memcpy(e, dr[i], sizeof dr[i]);
    sort(e + 1, e + n + 1);
    for (j = n; j >= n - 2; j--) gre[i][n - j] = e[j];
  }
  int ans[5], res = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      if (d[i][j].first <= 0) continue;
      for (l = 0; l < 3; l++) {
        x = gre[i][l].first;
        y = gre[i][l].second;
        if (y == j || x <= 0) continue;
        for (p = 0; p < 3; p++) {
          z = ge[j][p].first;
          t = ge[j][p].second;
          if (t == y || t == i || z <= 0) continue;
          if (res < x + d[i][j].first + z) {
            res = x + d[i][j].first + z;
            ans[0] = y;
            ans[1] = i;
            ans[2] = j;
            ans[3] = t;
          }
        }
      }
    }
  for (i = 0; i < 4; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
