#include <bits/stdc++.h>
using namespace std;
vector<int> v[3005];
vector<pair<int, int> > d[3005], d2[3005];
int dd[3005][3005];
bool vis[3005];
void bfs(const int st) {
  queue<int> q;
  q.push(st);
  d[st][st].first = 0;
  dd[st][st] = 0;
  vis[st] = true;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (int i = 0; i < v[node].size(); i++) {
      if (!vis[v[node][i]]) {
        vis[v[node][i]] = true;
        d[st][v[node][i]].first = d[st][node].first + 1;
        dd[st][v[node][i]] = d[st][v[node][i]].first;
        q.push(v[node][i]);
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < (m); i++) {
    scanf("%d%d", &a, &b);
    v[a - 1].push_back(b - 1);
  }
  for (int i = 0; i < (n); i++) {
    d[i].resize(n);
    d2[i].resize(n);
    for (int j = 0; j < (n); j++) {
      d[i][j].first = dd[i][j] = -100000;
      d[i][j].second = j;
    }
  }
  for (int i = 0; i < (n); i++) {
    memset(vis, 0, sizeof(vis));
    bfs(i);
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      d2[j][i] = d[i][j];
      d2[j][i].second = i;
    }
  }
  for (int i = 0; i < (n); i++) {
    sort(d[i].begin(), d[i].end(), greater<pair<int, int> >());
    sort(d2[i].begin(), d2[i].end(), greater<pair<int, int> >());
  }
  int ans[4], mx = 0;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      if (i == j) {
        continue;
      }
      int sp1 = 0, sp2 = 0;
      while (d2[i][sp1].second == j || d2[i][sp1].second == i) {
        sp1++;
      }
      if (d[j][sp2].second == i || d[j][sp2].second == j) {
        sp2++;
      }
      if (d2[i][sp1].second != d[j][sp2].second) {
        int val = dd[i][j] + d2[i][sp1].first + d[j][sp2].first;
        if (val > mx) {
          mx = val;
          ans[0] = d2[i][sp1].second;
          ans[3] = d[j][sp2].second;
          ans[1] = i;
          ans[2] = j;
        }
      } else {
        int tmp = sp1;
        while (d2[i][sp1].second == j || d2[i][sp1].second == i ||
               d2[i][sp1].second == d[j][sp2].second) {
          sp1++;
        }
        int val = dd[i][j] + d2[i][sp1].first + d[j][sp2].first;
        if (val > mx) {
          mx = val;
          ans[0] = d2[i][sp1].second;
          ans[3] = d[j][sp2].second;
          ans[1] = i;
          ans[2] = j;
        }
        sp1 = tmp;
        while (d[j][sp2].second == i || d[j][sp2].second == j ||
               d[j][sp2].second == d2[i][sp1].second) {
          sp2++;
        }
        val = dd[i][j] + d2[i][sp1].first + d[j][sp2].first;
        if (val > mx) {
          mx = val;
          ans[0] = d2[i][sp1].second;
          ans[3] = d[j][sp2].second;
          ans[1] = i;
          ans[2] = j;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) cout << ans[i] + 1 << " ";
  cout << ans[3] + 1 << endl;
  return 0;
}
