#include <bits/stdc++.h>
using namespace std;
int n;
int ki[3001][4], kiv[3001][4];
int kl[3001][4], klv[3001][4];
int d[3001][3001];
int v[3001];
vector<int> G[3001];
struct Edge {
  int from;
  int to;
};
Edge edge[5001];
void dij(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  for (int i = 1; i <= n; i++) {
    v[i] = 0;
    d[s][i] = 0x3f3f3f3f;
  }
  Q.push((pair<int, int>){0, s});
  d[s][s] = 0;
  while (!Q.empty()) {
    pair<int, int> x = Q.top();
    Q.pop();
    int u = x.second;
    if (v[u]) continue;
    v[u] = 1;
    for (int i = 0; i < G[u].size(); i++) {
      Edge &e = edge[G[u][i]];
      if (d[s][e.to] > d[s][u] + 1) {
        d[s][e.to] = d[s][u] + 1;
        Q.push((pair<int, int>){d[s][e.to], e.to});
      }
    }
  }
}
int main() {
  int m, a, b, c, di, sum, k, t, l, i, j, ff, tt, p, q;
  while (scanf("%d %d", &n, &m) == 2 && (n + m)) {
    memset(ki, 0, sizeof(ki));
    memset(kl, 0, sizeof(kl));
    memset(kiv, 0, sizeof(kiv));
    memset(klv, 0, sizeof(klv));
    for (i = 1; i <= n; i++) G[i].clear();
    sum = 0;
    for (i = 0; i < m; i++) {
      scanf("%d %d", &ff, &tt);
      edge[i].from = ff;
      edge[i].to = tt;
      G[ff].push_back(i);
    }
    for (i = 1; i <= n; i++) dij(i);
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) {
        if (d[i][j] > ki[i][1] && d[i][j] != 0x3f3f3f3f) {
          ki[i][3] = ki[i][2];
          kiv[i][3] = kiv[i][2];
          ki[i][2] = ki[i][1];
          kiv[i][2] = kiv[i][1];
          ki[i][1] = d[i][j];
          kiv[i][1] = j;
        } else if (d[i][j] > ki[i][2] && d[i][j] != 0x3f3f3f3f) {
          ki[i][3] = ki[i][2];
          kiv[i][3] = kiv[i][2];
          ki[i][2] = d[i][j];
          kiv[i][2] = j;
        } else if (d[i][j] > ki[i][3] && d[i][j] != 0x3f3f3f3f) {
          ki[i][3] = d[i][j];
          kiv[i][3] = j;
        }
        if (d[i][j] > kl[j][1] && d[i][j] != 0x3f3f3f3f) {
          kl[j][3] = kl[j][2];
          klv[j][3] = klv[j][2];
          kl[j][2] = kl[j][1];
          klv[j][2] = klv[j][1];
          kl[j][1] = d[i][j];
          klv[j][1] = i;
        } else if (d[i][j] > kl[j][2] && d[i][j] != 0x3f3f3f3f) {
          kl[j][3] = kl[j][2];
          klv[j][3] = klv[j][2];
          kl[j][2] = d[i][j];
          klv[j][2] = i;
        } else if (d[i][j] > kl[j][3] && d[i][j] != 0x3f3f3f3f) {
          kl[j][3] = d[i][j];
          klv[j][3] = i;
        }
      }
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) {
        if (i == j) continue;
        if (d[i][j] == 0x3f3f3f3f) continue;
        for (int k1 = 1; k1 <= 3; k1++)
          for (int k2 = 1; k2 <= 3; k2++) {
            if (klv[i][k1] == j || klv[i][k1] == 0) continue;
            t = klv[i][k1];
            if (kiv[j][k2] == t || kiv[j][k2] == i || kiv[j][k2] == 0) continue;
            l = kiv[j][k2];
            if (sum < d[t][i] + d[i][j] + d[j][l]) {
              sum = d[t][i] + d[i][j] + d[j][l];
              a = t;
              b = i;
              c = j;
              di = l;
            }
          }
      }
    printf("%d %d %d %d\n", a, b, c, di);
  }
  return 0;
}
