#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, int p) {
  if (p == 0) return 1;
  long long my = bigmod(b, p / 2);
  my *= my;
  my %= 1000000007;
  if (p & 1) my *= b, my %= 1000000007;
  return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
int cost[3005][3005], n, m;
bool visit[3005];
vector<int> g[3005];
void bfs(int s) {
  memset(visit, 0, sizeof(visit));
  queue<int> q;
  q.push(s);
  visit[s] = 1;
  while (q.empty() == 0) {
    int u = q.front();
    q.pop();
    int i, len = g[u].size();
    for (i = 0; i < len; i++) {
      int v = g[u][i];
      if (visit[v] == 0) {
        visit[v] = 1;
        cost[s][v] = cost[s][u] + 1;
        q.push(v);
      }
    }
  }
}
int far[3005][3], fs[3005];
void computefarthest(int a) {
  int i, idx1 = -1, idx2 = -1, idx3 = -1, mx;
  mx = -1;
  for (i = 1; i <= n; i++) {
    if (i == a) continue;
    if (cost[i][a] == 0) continue;
    if (cost[i][a] > mx) {
      mx = cost[i][a];
      idx1 = i;
    }
  }
  if (idx1 != -1) far[a][fs[a]++] = idx1;
  mx = -1;
  for (i = 1; i <= n; i++) {
    if (i == a || i == idx1) continue;
    if (cost[i][a] == 0) continue;
    if (cost[i][a] > mx) {
      mx = cost[i][a];
      idx2 = i;
    }
  }
  if (idx2 != -1) far[a][fs[a]++] = idx2;
  mx = -1;
  for (i = 1; i <= n; i++) {
    if (i == a || i == idx1 || i == idx2) continue;
    if (cost[i][a] == 0) continue;
    if (cost[i][a] > mx) {
      mx = cost[i][a];
      idx3 = i;
    }
  }
  if (idx3 != -1) far[a][fs[a]++] = idx3;
}
int farr[3005][3], fsr[3005];
void computefarthestreal(int a) {
  int i, idx1 = -1, idx2 = -1, idx3 = -1, mx;
  mx = -1;
  for (i = 1; i <= n; i++) {
    if (i == a) continue;
    if (cost[a][i] == 0) continue;
    if (cost[a][i] > mx) {
      mx = cost[a][i];
      idx1 = i;
    }
  }
  if (idx1 != -1) farr[a][fsr[a]++] = idx1;
  mx = -1;
  for (i = 1; i <= n; i++) {
    if (i == a || i == idx1) continue;
    if (cost[a][i] == 0) continue;
    if (cost[a][i] > mx) {
      mx = cost[a][i];
      idx2 = i;
    }
  }
  if (idx2 != -1) farr[a][fsr[a]++] = idx2;
  mx = -1;
  for (i = 1; i <= n; i++) {
    if (i == a || i == idx1 || i == idx2) continue;
    if (cost[a][i] == 0) continue;
    if (cost[a][i] > mx) {
      mx = cost[a][i];
      idx3 = i;
    }
  }
  if (idx3 != -1) farr[a][fsr[a]++] = idx3;
}
int f1, f2, f3, f4, ok;
int r1, r2, r3, r4;
void lol(int a, int b) {
  int i, j, mx = 0;
  ok = 0;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      int x = far[a][i];
      int y = farr[b][j];
      if (x != 0 && y != 0) {
        if (x != y && x != a && x != b && y != a && y != b) {
          int val = cost[x][a] + cost[a][b] + cost[b][y];
          ok = 1;
          if (val > mx) {
            mx = val;
            f1 = x;
            f2 = a;
            f3 = b;
            f4 = y;
          }
        }
      }
    }
  }
}
int main() {
  int i, x, y, j;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
  }
  for (i = 1; i <= n; i++) bfs(i);
  for (i = 1; i <= n; i++) computefarthest(i);
  for (i = 1; i <= n; i++) computefarthestreal(i);
  int mx = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i == j) continue;
      if (cost[i][j] == 0) continue;
      lol(i, j);
      int val = cost[f1][f2] + cost[f2][f3] + cost[f3][f4];
      if (val > mx) {
        mx = val;
        r1 = f1;
        r2 = f2;
        r3 = f3;
        r4 = f4;
      }
    }
  }
  printf("%d %d %d %d\n", r1, r2, r3, r4);
  return 0;
}
