#include <bits/stdc++.h>
using namespace std;
int d[3010][3010];
int n, m;
int q[3000 * 3000 + 10];
int greate[3000 + 10][3];
int back[3000 + 10][3];
vector<vector<int> > g;
void bfs(int v) {
  for (int i = 0; i <= n; i++) {
    d[v][i] = 1e9;
  }
  d[v][v] = 0;
  int l = 0, r = 0;
  q[r++] = v;
  while (l < r) {
    int top = q[l++];
    for (int ix = 0; ix < (int)g[top].size(); ix++) {
      int to = g[top][ix];
      if (d[v][to] > d[v][top] + 1) {
        d[v][to] = d[v][top] + 1;
        q[r++] = to;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (x == y) continue;
    g[x].push_back(y);
  }
  for (int i = 0; i < n; i++) {
    bfs(i);
  }
  for (int i = 0; i <= n; i++) d[n][i] = d[i][n] = 0;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < 3; k++) greate[i][k] = back[i][k] = n;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] == 1e9) continue;
      if (d[i][greate[i][0]] < d[i][j]) {
        greate[i][2] = greate[i][1];
        greate[i][1] = greate[i][0];
        greate[i][0] = j;
      } else if (d[i][greate[i][1]] < d[i][j]) {
        greate[i][2] = greate[i][1];
        greate[i][1] = j;
      } else if (d[i][greate[i][2]] < d[i][j]) {
        greate[i][2] = j;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] == 1e9) continue;
      if (d[back[j][0]][j] < d[i][j]) {
        back[j][2] = back[j][1];
        back[j][1] = back[j][0];
        back[j][0] = i;
      } else if (d[back[j][1]][j] < d[i][j]) {
        back[j][2] = back[j][1];
        back[j][1] = i;
      } else if (d[back[j][2]][j] < d[i][j]) {
        back[j][2] = i;
      }
    }
  }
  int result[4] = {0};
  int length = 0;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < n; b++) {
      if (a == b) continue;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (d[back[a][i]][a] == 1e9 || d[a][b] == 1e9 ||
              d[b][greate[b][j]] == 1e9 || back[a][i] == n || greate[b][j] == n)
            continue;
          int l = d[back[a][i]][a] + d[a][b] + d[b][greate[b][j]];
          if (back[a][i] != b && back[a][i] != greate[b][j] &&
              greate[b][j] != a && length < l) {
            result[0] = back[a][i];
            result[1] = a;
            result[2] = b;
            result[3] = greate[b][j];
            length = l;
            goto ee;
          }
        }
      }
    ee:;
    }
  }
  for (int i = 0; i < 4; i++) {
    cout << result[i] + 1 << " ";
  }
  return 0;
}
