#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  assert(scanf("%d%d", &n, &m) == 2);
  vector<int> g[n];
  for (int i = 0; i < m; i++) {
    int a, b;
    assert(scanf("%d%d", &a, &b) == 2);
    a--, b--;
    g[a].push_back(b);
  }
  int d[n][n];
  for (int st = 0; st < n; st++) {
    int q[n], qs, qz;
    qs = 0, qz = 0;
    q[qs + qz++] = st;
    memset(d[st], -1, sizeof(d[st][0]) * n);
    d[st][st] = 0;
    while (qz > 0) {
      int u = q[qs++];
      qz--;
      for (int i = 0; i < (int)g[u].size(); i++) {
        if (d[st][g[u][i]] != -1) continue;
        d[st][g[u][i]] = d[st][u] + 1;
        q[qs + qz++] = g[u][i];
      }
    }
  }
  int sm[n][4];
  int rm[n][4];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) sm[i][j] = rm[i][j] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int k;
      if (d[i][j] == -1) continue;
      sm[i][k = 3] = j;
      while (k > 0 && d[i][j] > d[i][sm[i][k - 1]]) {
        swap(sm[i][k - 1], sm[i][k]);
        k--;
      }
      rm[j][k = 3] = i;
      while (k > 0 && d[i][j] > d[rm[j][k - 1]][j]) {
        swap(rm[j][k - 1], rm[j][k]);
        k--;
      }
    }
  }
  int ans = 0;
  int res[4];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j || d[i][j] == -1) continue;
      for (int ti = 0; ti < 3; ti++)
        for (int tj = 0; tj < 3; tj++) {
          if (rm[i][ti] == i || rm[i][ti] == j) continue;
          if (sm[j][tj] == i || sm[j][tj] == j) continue;
          if (rm[i][ti] == sm[j][tj]) continue;
          int current = d[rm[i][ti]][i] + d[i][j] + d[j][sm[j][tj]];
          if (current <= ans) continue;
          ans = current;
          res[0] = rm[i][ti];
          res[1] = i;
          res[2] = j;
          res[3] = sm[j][tj];
        }
    }
  }
  assert(ans > 0);
  for (int i = 0; i < 4; i++) printf("%d%c", res[i] + 1, "\n "[i < 3]);
  return 0;
}
