#include <bits/stdc++.h>
using namespace std;
const int maxN = 3011;
const int oo = 1e9 + 11;
int n, m;
pair<int, int> d[maxN][maxN], maxx[maxN][5], maxx2[maxN][5];
vector<int> vt[maxN], vt2[maxN];
bool cmp(pair<int, int> A, pair<int, int> B) { return A.second < B.second; }
void BFS(int x) {
  queue<int> qu;
  for (int i = 1; i <= n; i++) d[x][i] = pair<int, int>(oo, i);
  d[x][x].first = 0;
  qu.push(x);
  while (qu.size() > 0) {
    int u = qu.front();
    qu.pop();
    for (int i = 0; i < vt[u].size(); i++) {
      int v = vt[u][i];
      if (d[x][v].first > d[x][u].first + 1) {
        d[x][v].first = d[x][u].first + 1;
        qu.push(v);
      }
    }
  }
  sort(d[x] + 1, d[x] + n + 1);
  int cnt = 0;
  for (int i = n; i >= 1; i--)
    if (d[x][i].first != oo) {
      cnt++;
      maxx[x][cnt] = d[x][i];
      if (cnt == 3) break;
    }
  sort(d[x] + 1, d[x] + n + 1, cmp);
}
void BFS2(int x) {
  queue<int> qu;
  for (int i = 1; i <= n; i++) d[x][i] = pair<int, int>(oo, i);
  d[x][x].first = 0;
  qu.push(x);
  while (qu.size() > 0) {
    int u = qu.front();
    qu.pop();
    for (int i = 0; i < vt2[u].size(); i++) {
      int v = vt2[u][i];
      if (d[x][v].first > d[x][u].first + 1) {
        d[x][v].first = d[x][u].first + 1;
        qu.push(v);
      }
    }
  }
  sort(d[x] + 1, d[x] + n + 1);
  int cnt = 0;
  for (int i = n; i >= 1; i--)
    if (d[x][i].first != oo) {
      cnt++;
      maxx2[x][cnt] = d[x][i];
      if (cnt == 3) break;
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (u == v) continue;
    vt[u].push_back(v);
    vt2[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    BFS2(i);
    BFS(i);
  }
  int lmax = 0;
  pair<pair<int, int>, pair<int, int> > res;
  for (int B = 1; B <= n; B++)
    for (int C = 1; C <= n; C++) {
      if (B == C) continue;
      if (d[B][C].first == oo) continue;
      for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= 3; j++) {
          int A = maxx2[B][i].second, D = maxx[C][j].second;
          if (A == 0 || D == 0) continue;
          if (A == B || A == C || A == D || B == D || C == D) continue;
          if (lmax < maxx2[B][i].first + d[B][C].first + maxx[C][j].first) {
            lmax = maxx2[B][i].first + d[B][C].first + maxx[C][j].first;
            res = pair<pair<int, int>, pair<int, int> >(pair<int, int>(A, B),
                                                        pair<int, int>(C, D));
          }
        }
    }
  cout << res.first.first << " " << res.first.second << " " << res.second.first
       << " " << res.second.second;
  return 0;
}
