#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[2000005];
long long int visited[4005], primes[1000005];
long long int mini = INT64_MAX;
void dfs(long long int x, long long int p, long long int val,
         long long int count) {
  if (count >= 3) return;
  if (visited[x]) return;
  count++;
  if (count == 3) {
    for (auto i : adj[x]) {
      if (i == val) {
        long long int zp = adj[val].size() + adj[x].size() + adj[p].size() - 6;
        if (zp < mini) mini = zp;
      }
    }
    return;
  }
  for (auto i : adj[x]) {
    if (i == p) continue;
    dfs(i, x, val, count);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    long long int i, j, n, m;
    cin >> n >> m;
    for (i = 0; i < m; i++) {
      long long int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    for (i = 1; i <= n; i++) {
      long long int count = 0;
      dfs(i, 0, i, count);
      visited[i] = 1;
    }
    if (mini == INT64_MAX)
      cout << -1 << "\n";
    else
      cout << mini << "\n";
  }
  return 0;
}
