#include <bits/stdc++.h>
using namespace std;
int MAX_N = 3005;
int inf = 1e9;
vector<vector<int> > normal_graph(MAX_N);
vector<vector<int> > reversed_graph(MAX_N);
vector<vector<int> > normal_distance(MAX_N, vector<int>(MAX_N, inf));
vector<vector<int> > reversed_distance(MAX_N, vector<int>(MAX_N, inf));
int main() {
  for (int i = 0; i < MAX_N; i++) {
    normal_distance[i][i] = 0;
    reversed_distance[i][i] = 0;
  }
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int tmp1, tmp2;
    scanf("%d %d", &tmp1, &tmp2);
    tmp1--;
    tmp2--;
    normal_graph[tmp1].push_back(tmp2);
    reversed_graph[tmp2].push_back(tmp1);
  }
  for (int start = 0; start < n; start++) {
    queue<int> q;
    q.push(start);
    vector<bool> visited(n, false);
    visited[start] = true;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int i = 0; i < normal_graph[now].size(); i++) {
        int neigh = normal_graph[now][i];
        if (!visited[neigh]) {
          normal_distance[start][neigh] = normal_distance[start][now] + 1;
          q.push(neigh);
          visited[neigh] = true;
        }
      }
    }
    q.push(start);
    for (int i = 0; i < n; i++) {
      visited[i] = false;
    }
    visited[start] = true;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int i = 0; i < reversed_graph[now].size(); i++) {
        int neigh = reversed_graph[now][i];
        if (!visited[neigh]) {
          reversed_distance[start][neigh] = reversed_distance[start][now] + 1;
          q.push(neigh);
          visited[neigh] = true;
        }
      }
    }
  }
  vector<vector<pair<int, int> > > normal_best(n);
  vector<vector<pair<int, int> > > reversed_best(n);
  for (int i = 0; i < n; i++) {
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        pq;
    for (int j = 0; j < n; j++) {
      if (i == j) {
        pq.push(make_pair(-1, -1));
      } else {
        if (normal_distance[i][j] == inf) {
          pq.push(make_pair(-1, -1));
        } else {
          pq.push(make_pair(normal_distance[i][j], j));
        }
      }
      if (pq.size() > 3) {
        pq.pop();
      }
    }
    while (!pq.empty()) {
      pair<int, int> p = pq.top();
      pq.pop();
      normal_best[i].push_back(p);
    }
    for (int j = 0; j < n; j++) {
      if (i == j) {
        pq.push(make_pair(-1, -1));
      } else {
        if (reversed_distance[i][j] == inf) {
          pq.push(make_pair(-1, -1));
        } else {
          pq.push(make_pair(reversed_distance[i][j], j));
        }
      }
      if (pq.size() > 3) {
        pq.pop();
      }
    }
    while (!pq.empty()) {
      pair<int, int> p = pq.top();
      pq.pop();
      reversed_best[i].push_back(p);
    }
  }
  int maxx = -1;
  vector<int> ans(4, -1);
  for (int two = 0; two < n; two++) {
    for (int three = 0; three < n; three++) {
      if (two == three) {
        continue;
      }
      int sum = normal_distance[two][three];
      if (sum == inf) {
        continue;
      }
      for (int i = 0; i < reversed_best[two].size(); i++) {
        for (int j = 0; j < normal_best[three].size(); j++) {
          int one = reversed_best[two][i].second;
          int four = normal_best[three][j].second;
          if (one != -1 && four != -1 && one != two && one != three &&
              one != four && two != four && three != four) {
            if (one == 5 && four == 2 && two == 4 && three == 1) {
            }
            sum = normal_distance[two][three] + reversed_best[two][i].first +
                  normal_best[three][j].first;
            if (sum > maxx) {
              maxx = sum;
              ans[0] = one;
              ans[1] = two;
              ans[2] = three;
              ans[3] = four;
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    if (i != 0) {
      printf(" ");
    }
    printf("%d", ans[i] + 1);
  }
  printf("\n");
  return 0;
}
