#include <bits/stdc++.h>
using namespace std;
vector<int> v[3333], out[3333], in[3333];
int dis[3333][3333], D[3333], id[3333];
int n, m;
bool cmp(int i, int j) { return D[i] > D[j]; }
int main() {
  int x, y;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) dis[i][j] = -1;
    dis[i][i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      x = q.front();
      q.pop();
      for (int j = 0; j < v[x].size(); j++) {
        y = v[x][j];
        if (dis[i][y] != -1) continue;
        dis[i][y] = dis[i][x] + 1;
        q.push(y);
      }
    }
    for (int j = 1; j <= n; j++) D[j] = dis[i][j], id[j] = j;
    sort(id + 1, id + n + 1, cmp);
    for (int j = 1; j <= min(5, n); j++) out[i].push_back(id[j]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) id[j] = j, D[j] = dis[j][i];
    sort(id + 1, id + n + 1, cmp);
    for (int j = 1; j <= min(5, n); j++) in[i].push_back(id[j]);
  }
  int ans = 0, a, b, c, d;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j || dis[i][j] < 0) continue;
      for (int k = 0; k < out[j].size(); k++) {
        int J = out[j][k];
        if (dis[j][J] <= 0) continue;
        if (J == i) continue;
        for (int l = 0; l < in[i].size(); l++) {
          int I = in[i][l];
          if (dis[I][i] <= 0 || I == J || I == j) continue;
          int tp = dis[I][i] + dis[i][j] + dis[j][J];
          if (tp > ans) ans = tp, a = I, b = i, c = j, d = J;
        }
      }
    }
  printf("%d %d %d %d\n", a, b, c, d);
}
