#include <bits/stdc++.h>
using namespace std;
int n, m, d[3005][3005];
int bf[3005][3], bt[3005][3], sel[3005];
vector<int> v[3005];
int q[3005], l, r;
int res[4], val;
void calc(int X) {
  for (int i = (1); i <= (n); i++) d[X][i] = 9999999;
  d[X][X] = 0;
  l = 0;
  q[r = 1] = X;
  while (l < r) {
    int cur = q[++l];
    for (int i = (0); i <= ((int)v[cur].size() - 1); i++) {
      int nx = v[cur][i];
      if (d[X][nx] > d[X][cur] + 1) {
        d[X][nx] = d[X][cur] + 1;
        q[++r] = nx;
      }
    }
  }
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (m); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
  }
  for (int i = (1); i <= (n); i++) calc(i);
  for (int i = (1); i <= (n); i++) {
    memset(sel, 0, sizeof(sel));
    for (int k = (1); k <= (n); k++)
      if (d[k][i] == 9999999 || d[k][i] == 0) sel[k] = 1;
    for (int j = (0); j <= (2); j++) {
      for (int k = (1); k <= (n); k++)
        if (!sel[k] && d[k][i] > d[bf[i][j]][i]) {
          bf[i][j] = k;
        }
      sel[bf[i][j]] = 1;
    }
    memset(sel, 0, sizeof(sel));
    for (int k = (1); k <= (n); k++)
      if (d[i][k] == 9999999 || d[i][k] == 0) sel[k] = 1;
    for (int j = (0); j <= (2); j++) {
      for (int k = (1); k <= (n); k++)
        if (!sel[k] && d[i][k] > d[i][bt[i][j]]) {
          bt[i][j] = k;
        }
      sel[bt[i][j]] = 1;
    }
  }
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++)
      if (j != i && d[i][j] != 9999999) {
        for (int a = (0); a <= (2); a++)
          for (int b = (0); b <= (2); b++) {
            int i2 = bf[i][a];
            int j2 = bt[j][b];
            if (i2 == 0 || j2 == 0 || i2 == j2 || i2 == j || j2 == i) continue;
            if (d[i2][i] + d[i][j] + d[j][j2] > val) {
              val = d[i2][i] + d[i][j] + d[j][j2];
              res[0] = i2;
              res[1] = i;
              res[2] = j;
              res[3] = j2;
            }
          }
      }
  for (int i = (0); i <= (3); i++) printf("%d%c", res[i], i == 3 ? '\n' : ' ');
  return 0;
}
