#include <bits/stdc++.h>
using namespace std;
int N, M;
const int INF = 1e9;
int D[3000][3000];
vector<int> E[3000];
vector<pair<int, int> > BB[3000];
vector<pair<int, int> > CC[3000];
void bfs2(int s) {
  D[s][s] = 0;
  vector<int> v1, v2;
  vector<int>& f = v1;
  vector<int>& t = v2;
  f.push_back(s);
  int d = 0;
  while (((int)(f).size())) {
    for (auto&& cur : f) {
      for (auto&& nex : E[cur]) {
        if (D[s][nex] > INF) {
          D[s][nex] = d + 1;
          t.push_back(nex);
        }
      }
    }
    swap(f, t);
    t.clear();
    d++;
  }
}
void bfs1(int s) {
  D[s][s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int cur = q.front();
    q.pop();
    for (auto&& nex : E[cur]) {
      if (D[s][nex] > D[s][cur] + 1) {
        D[s][nex] = D[s][cur] + 1;
        q.push(nex);
      }
    }
  }
}
void Main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < (M); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    E[u - 1].push_back(v - 1);
  }
  memset(D, 0x3f, sizeof(D));
  for (int s = 0; s < (N); s++) {
    bfs1(s);
  }
  for (int x = 0; x < (N); x++) {
    for (int y = 0; y < (N); y++)
      if (x != y) {
        if (D[x][y] < INF) {
          BB[y].push_back({D[x][y], x});
          CC[x].push_back({D[x][y], y});
        }
      }
  }
  for (int x = 0; x < (N); x++) {
    sort((BB[x]).begin(), (BB[x]).end());
    reverse((BB[x]).begin(), (BB[x]).end());
    if (((int)(BB[x]).size()) > 3) BB[x].resize(3);
    sort((CC[x]).begin(), (CC[x]).end());
    reverse((CC[x]).begin(), (CC[x]).end());
    if (((int)(CC[x]).size()) > 3) CC[x].resize(3);
  }
  int ma = -1;
  int c1, c2, c3, c4;
  for (int b = 0; b < (N); b++)
    for (int c = 0; c < (N); c++)
      if (b != c && D[b][c] < INF) {
        vector<int> aa;
        for (auto&& dv : BB[b]) {
          int v = dv.second;
          if (v != c) {
            aa.push_back(v);
            if (((int)(aa).size()) == 2) break;
          }
        }
        vector<int> dd;
        for (auto&& dv : CC[c]) {
          int v = dv.second;
          if (v != b) {
            dd.push_back(v);
            if (((int)(dd).size()) == 2) break;
          }
        }
        for (auto&& a : aa)
          for (auto&& d : dd) {
            if (a != d) {
              int dist = D[a][b] + D[b][c] + D[c][d];
              if (dist > ma) {
                ma = dist;
                c1 = a;
                c2 = b;
                c3 = c;
                c4 = d;
              }
            }
          }
      }
  (void)printf("%d %d %d %d\n", c1 + 1, c2 + 1, c3 + 1, c4 + 1);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  Main();
  return 0;
}
