#include <bits/stdc++.h>
using namespace std;
void solve(long long test_number);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(9);
  cerr.setf(ios::fixed);
  cerr.precision(3);
  long long n = 1;
  for (long long i = 0; i < n; i++) {
    solve(i + 1);
  }
  return 0;
}
const long long MAXN = 3010;
long long n, m;
vector<long long> g[MAXN];
vector<long long> rg[MAXN];
long long d[MAXN][MAXN];
long long rd[MAXN][MAXN];
pair<long long, long long> a[MAXN];
pair<long long, long long> bst[MAXN][3];
pair<long long, long long> rbst[MAXN][3];
long long sz[MAXN];
long long rsz[MAXN];
void bfs(long long st) {
  queue<long long> q;
  q.push(st);
  d[st][st] = 0;
  while (!q.empty()) {
    long long v = q.front();
    q.pop();
    for (auto to : g[v]) {
      if (d[st][to] == ((long long)(1e+9))) {
        d[st][to] = d[st][v] + 1;
        q.push(to);
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    a[i] = {d[st][i], i};
  }
  sort(a, a + n, greater<pair<long long, long long> >());
  for (long long i = 0; i < n; i++) {
    if (a[i].first != ((long long)(1e+9)) && a[i].second != st) {
      bst[st][sz[st]++] = a[i];
      if (sz[st] == 3) {
        break;
      }
    }
  }
}
void rbfs(long long st) {
  queue<long long> q;
  q.push(st);
  rd[st][st] = 0;
  while (!q.empty()) {
    long long v = q.front();
    q.pop();
    for (auto to : rg[v]) {
      if (rd[st][to] == ((long long)(1e+9))) {
        rd[st][to] = rd[st][v] + 1;
        q.push(to);
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    a[i] = {rd[st][i], i};
  }
  sort(a, a + n, greater<pair<long long, long long> >());
  for (long long i = 0; i < n; i++) {
    if (a[i].first != ((long long)(1e+9)) && a[i].second != st) {
      rbst[st][rsz[st]++] = a[i];
      if (rsz[st] == 3) {
        break;
      }
    }
  }
}
void solve(long long test_number) {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      d[i][j] = rd[i][j] = ((long long)(1e+9));
    }
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    rg[v].push_back(u);
  }
  for (long long i = 0; i < n; i++) {
    bfs(i);
    rbfs(i);
  }
  long long res = -1;
  long long a = -1, b = -1, c = -1, e = -1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (d[i][j] == ((long long)(1e+9))) d[i][j] = -((long long)(1e+9));
      if (rd[i][j] == ((long long)(1e+9))) rd[i][j] = -((long long)(1e+9));
    }
  }
  for (long long v = 0; v < n; v++) {
    for (long long u = 0; u < n; u++) {
      if (v != u) {
        long long cur = d[v][u];
        long long best = -2 * ((long long)(1e+9)), aa = -1, ee = -1;
        for (long long i = 0; i < rsz[v]; i++) {
          for (long long j = 0; j < sz[u]; j++) {
            long long ca = rbst[v][i].second;
            long long ce = bst[u][j].second;
            if (ca != ce && ca != v && ca != u && ce != v && ce != u) {
              if (best < rd[v][ca] + d[u][ce]) {
                best = rd[v][ca] + d[u][ce];
                aa = ca, ee = ce;
              }
            }
          }
        }
        if (best > 0) {
          cur += best;
          if (cur > res) {
            a = aa, b = v, c = u, e = ee;
            res = cur;
          }
        }
      }
    }
  }
  cout << a + 1 << " " << b + 1 << " " << c + 1 << " " << e + 1 << endl;
}
