#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int N = 3e3 + 77, maxn = 200000, inf = 1e9 + 77, px[7] = {0, 0, -1, 1},
          py[7] = {-1, 1, 0, 0};
const long double pi = 3.14159265359;
int n, m, d[N][N];
vector<int> g[N], rg[N];
bool used[N][N];
void bfs(int x) {
  queue<int> q;
  q.push(x);
  used[x][x] = 1;
  d[x][x] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i];
      if (used[x][to]) continue;
      used[x][to] = 1;
      d[x][to] = d[x][v] + 1;
      q.push(to);
    }
  }
}
vector<pair<int, int> > l[N], r[N];
int a[7];
bool inp[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (u == v || inp[u][v]) continue;
    inp[u][v] = 1;
    g[u].push_back(v);
    rg[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      d[i][j] = inf;
    }
  }
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (d[j][i] != inf && i != j) {
        l[i].push_back(make_pair(d[j][i], j));
      }
    }
    sort(l[i].begin(), l[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (d[i][j] != inf && i != j) {
        r[i].push_back(make_pair(d[i][j], j));
      }
    }
    sort(r[i].begin(), r[i].end());
  }
  int ans = -123;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || d[i][j] == inf) {
        continue;
      }
      bool flag1 = 1;
      int path = d[i][j];
      int k = l[i].size() - 1;
      int v1 = -1, d1;
      while (k >= 0) {
        if (l[i][k].second != i && l[i][k].second != j) {
          v1 = l[i][k].second;
          d1 = l[i][k].first;
          break;
        }
        k--;
      }
      if (v1 == -1) flag1 = 0;
      path += d1;
      k = r[j].size() - 1;
      int v2 = -1, d2;
      while (k >= 0) {
        if (r[j][k].second != i && r[j][k].second != j &&
            r[j][k].second != v1) {
          v2 = r[j][k].second;
          d2 = r[j][k].first;
          break;
        }
        k--;
      }
      if (v2 == -1) flag1 = 0;
      path += d2;
      if (flag1 && path > ans) {
        ans = path;
        a[0] = v1;
        a[1] = i;
        a[2] = j;
        a[3] = v2;
      }
      path = d[i][j];
      k = r[j].size() - 1;
      v2 = -1;
      while (k >= 0) {
        if (r[j][k].second != i && r[j][k].second != j) {
          v2 = r[j][k].second;
          d2 = r[j][k].first;
          break;
        }
        k--;
      }
      if (v2 == -1) continue;
      path += d2;
      k = l[i].size() - 1;
      v1 = -1;
      while (k >= 0) {
        if (l[i][k].second != i && l[i][k].second != j &&
            l[i][k].second != v2) {
          v1 = l[i][k].second;
          d1 = l[i][k].first;
          break;
        }
        k--;
      }
      if (v1 == -1) continue;
      path += d1;
      if (path > ans) {
        ans = path;
        a[0] = v1;
        a[1] = i;
        a[2] = j;
        a[3] = v2;
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    if (i) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
}
