#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > f[3040], s[3040];
vector<int> g[3040];
int dis[3040][3040];
int n, m;
void bfs() {
  for (int i = 1; i <= n; i++) {
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int j = 0; j < g[u].size(); j++) {
        int w = g[u][j];
        if (dis[i][w] != 0x3f3f3f3f) continue;
        dis[i][w] = dis[i][u] + 1;
        q.push(w);
      }
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m) && n + m) {
    memset(dis, 0x3f, sizeof(dis));
    for (int i = 1; i <= n; i++) dis[i][i] = 0;
    for (int i = 1; i <= n; i++) g[i].clear(), s[i].clear(), f[i].clear();
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
    }
    bfs();
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i == j) continue;
        if (dis[i][j] != 0x3f3f3f3f)
          f[i].push_back(pair<int, int>(dis[i][j], j));
        if (dis[j][i] != 0x3f3f3f3f)
          s[i].push_back(pair<int, int>(dis[j][i], j));
      }
      sort(f[i].begin(), f[i].end());
      sort(s[i].begin(), s[i].end());
    }
    int r1, r2, r3, r4, res;
    int maxx = -1;
    for (int i = 1; i <= n; i++) {
      int a = f[i].size();
      for (int j = 1; j <= n; j++) {
        int b = s[j].size();
        if (i == j || dis[j][i] == 0x3f3f3f3f) continue;
        for (int k = a - 1; k >= a - 3 && k >= 0; k--) {
          if (f[i][k].second == j) continue;
          for (int y = b - 1; y >= b - 3 && y >= 0; y--) {
            if (f[i][k].second == s[j][y].second) continue;
            if (s[j][y].second == i) continue;
            res = dis[j][i] + s[j][y].first + f[i][k].first;
            if (res > maxx) {
              maxx = res;
              r1 = s[j][y].second, r2 = j, r3 = i, r4 = f[i][k].second;
            }
          }
        }
      }
    }
    printf("%d %d %d %d\n", r1, r2, r3, r4);
  }
}
