#include <bits/stdc++.h>
using namespace std;
const int N = 3005, M = 5005;
int first[N], tot;
struct Edge {
  int y, nex;
} edge[M];
int dis[N][N];
pair<int, int> L[N][4], R[N][4];
void addedge(int x, int y) {
  edge[tot] = (Edge){y, first[x]};
  first[x] = tot++;
}
void add(pair<int, int> L[], pair<int, int> t) {
  L[3] = t;
  for (int k = 2; k >= 0; --k)
    if (L[k] < L[k + 1])
      swap(L[k], L[k + 1]);
    else
      break;
}
int main() {
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  int n, m;
  scanf("%d%d", &n, &m);
  memset(first, -1, sizeof(first));
  tot = 0;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(x, y);
  }
  memset(dis, 63, sizeof(dis));
  for (int i = 1; i <= n; ++i) {
    dis[i][i] = 0;
    queue<int> que;
    que.push(i);
    while (!que.empty()) {
      int x = que.front();
      que.pop();
      for (int k = first[x]; k != -1; k = edge[k].nex) {
        int y = edge[k].y;
        if (dis[i][y] > dis[i][x] + 1) {
          dis[i][y] = dis[i][x] + 1;
          que.push(y);
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) dis[i][i] = dis[0][0];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (dis[i][j] <= m) {
        add(R[i], make_pair(dis[i][j], j));
        add(L[j], make_pair(dis[i][j], i));
      }
  int ans = -1;
  int p0, p1, p2, p3;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (dis[i][j] <= m) {
        for (int k = 0; k < 3; ++k)
          if (L[i][k].first > 0 && L[i][k].second != j) {
            int t1 = L[i][k].second, L1 = L[i][k].first;
            for (int l = 0; l < 3; ++l)
              if (R[j][l].first > 0 && R[j][l].second != i &&
                  R[j][l].second != t1) {
                int t2 = R[j][l].second, L2 = R[j][l].first;
                if (dis[i][j] + L1 + L2 > ans) {
                  ans = dis[i][j] + L1 + L2;
                  p0 = t1;
                  p1 = i;
                  p2 = j;
                  p3 = t2;
                }
              }
          }
      }
  cout << p0 << " " << p1 << " " << p2 << " " << p3 << endl;
}
