#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  map<int, int> m;
  int n, k;
  cin >> n >> k;
  vector<int> adj[n + 5];
  while (k--) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    m[a]++;
    m[b]++;
  }
  int x = INT_MAX;
  for (int i = 1; i <= n; i++) {
    if (m[i] < 2) continue;
    int visit[5000] = {0};
    queue<int> q;
    for (int j = 0; j < adj[i].size(); j++) {
      q.push(adj[i][j]);
      visit[adj[i][j]] = 1;
    }
    int p = m[i] - 2;
    while (!q.empty()) {
      int t = q.front();
      q.pop();
      for (int j = 0; j < adj[t].size(); j++) {
        if (visit[adj[t][j]]) {
          int mi = p + m[t] - 2 + m[adj[t][j]] - 2;
          x = min(x, mi);
        }
      }
    }
  }
  if (x == INT_MAX) {
    cout << -1;
    return 0;
  }
  cout << x;
}
