#include <bits/stdc++.h>
using namespace std;
const int MAX = 3005;
const int UNLINKED = INT_MAX;
int dist[MAX][MAX];
vector<int> route[MAX];
int n, m;
struct Link {
  int point;
  int dis;
  Link(int p, int d) : point(p), dis(d){};
};
vector<Link> firTosec[MAX];
vector<Link> secTofir[MAX];
void spfa(int x) {
  int inq[MAX];
  memset(inq, 0, sizeof(inq));
  for (int i = 1; i <= n; i++) dist[x][i] = UNLINKED;
  dist[x][x] = 0;
  queue<int> Q;
  Q.push(x);
  inq[x] = 1;
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    inq[now] = 0;
    for (int i = 0; i < route[now].size(); i++) {
      int next = route[now][i];
      if (dist[x][next] > dist[x][now] + 1) {
        dist[x][next] = dist[x][now] + 1;
        if (!inq[next]) {
          inq[next] = 1;
          Q.push(next);
        }
      }
    }
  }
}
bool cmp(Link a, Link b) { return a.dis > b.dis; }
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    route[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) spfa(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dist[i][j] != UNLINKED) firTosec[i].push_back(Link(j, dist[i][j]));
      if (dist[j][i] != UNLINKED) secTofir[i].push_back(Link(j, dist[j][i]));
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(firTosec[i].begin(), firTosec[i].end(), cmp);
    sort(secTofir[i].begin(), secTofir[i].end(), cmp);
  }
  int a = -1, b = -1, c = -1, d = -1, ans = 0;
  for (int u = 1; u <= n; u++) {
    for (int v = 1; v <= n; v++) {
      if (v == u) continue;
      for (int i = 0; i < 3 && i < secTofir[u].size(); i++) {
        int s = secTofir[u][i].point;
        if (s == u || s == v) continue;
        for (int j = 0; j < 3 && j < firTosec[v].size(); j++) {
          int t = firTosec[v][j].point;
          if (t == u || t == v) continue;
          if (s == t) continue;
          int tmp = dist[u][v] + secTofir[u][i].dis + firTosec[v][j].dis;
          if (tmp > ans) {
            ans = tmp;
            a = s;
            b = u;
            c = v;
            d = t;
          }
        }
      }
    }
  }
  cout << a << ' ' << b << ' ' << c << ' ' << d << '\n';
  return 0;
}
