#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
const int INF = 0x3f3f3f3f;
vector<int> G[maxn];
int mat[maxn][maxn];
int n, m;
int dis[maxn], inq[maxn];
void spfa(int s) {
  queue<int> Q;
  memset(inq, 0, sizeof(inq));
  for (int i = 0; i < n; i++) dis[i] = INF;
  dis[s] = 0;
  inq[s] = 1;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    inq[u] = false;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        if (!inq[v]) {
          Q.push(v);
          inq[v] = true;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    mat[s][i] = dis[i];
  }
}
int ma_out[maxn][3];
int ma_in[maxn][3];
void pre_ma() {
  for (int i = 0; i < n; i++) {
    ma_out[i][0] = ma_out[i][1] = ma_out[i][2] = -1;
    for (int j = 0; j < n; j++) {
      if (mat[i][j] >= INF) continue;
      if (ma_out[i][2] == -1 || mat[i][ma_out[i][2]] < mat[i][j]) {
        ma_out[i][0] = ma_out[i][1];
        ma_out[i][1] = ma_out[i][2];
        ma_out[i][2] = j;
      } else if (ma_out[i][1] == -1 || mat[i][ma_out[i][1]] < mat[i][j]) {
        ma_out[i][0] = ma_out[i][1];
        ma_out[i][1] = j;
      } else if (ma_out[i][0] == -1 || mat[i][ma_out[i][0]] < mat[i][j]) {
        ma_out[i][0] = j;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ma_in[i][0] = ma_in[i][1] = ma_in[i][2] = -1;
    for (int j = 0; j < n; j++) {
      if (mat[j][i] >= INF) continue;
      if (ma_in[i][2] == -1 || mat[ma_in[i][2]][i] < mat[j][i]) {
        ma_in[i][0] = ma_in[i][1];
        ma_in[i][1] = ma_in[i][2];
        ma_in[i][2] = j;
      } else if (ma_in[i][1] == -1 || mat[ma_in[i][1]][i] < mat[j][i]) {
        ma_in[i][0] = ma_in[i][1];
        ma_in[i][1] = j;
      } else if (ma_in[i][0] == -1 || mat[ma_in[i][0]][i] < mat[j][i]) {
        ma_in[i][0] = j;
      }
    }
  }
}
void init() {
  for (int i = 0; i < n; i++) G[i].clear();
}
int main() {
  while (scanf("%d%d", &n, &m) == 2 && n) {
    init();
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--, v--;
      G[u].push_back(v);
    }
    for (int i = 0; i < n; i++) spfa(i);
    pre_ma();
    int ans = -1;
    int nds[4] = {0};
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        if (mat[i][j] >= INF) continue;
        for (int k = 0; k < 3; k++) {
          for (int l = 0; l < 3; l++) {
            if (ma_in[i][k] == -1 || ma_out[j][l] == -1) continue;
            if (ma_in[i][k] == i || ma_in[i][k] == j ||
                ma_in[i][k] == ma_out[j][l])
              continue;
            if (ma_out[j][l] == i || ma_out[j][l] == j) continue;
            if (ans < mat[ma_in[i][k]][i] + mat[i][j] + mat[j][ma_out[j][l]]) {
              ans = mat[ma_in[i][k]][i] + mat[i][j] + mat[j][ma_out[j][l]];
              nds[0] = ma_in[i][k];
              nds[1] = i;
              nds[2] = j;
              nds[3] = ma_out[j][l];
            }
          }
        }
      }
    }
    printf("%d %d %d %d\n", nds[0] + 1, nds[1] + 1, nds[2] + 1, nds[3] + 1);
  }
  return 0;
}
