#include <bits/stdc++.h>
using namespace std;
long long n, m, ans = (unsigned long long)1e9;
vector<long long> adj[4001];
bool adj1[4001][4001], vis[4001];
void dfs(long long s) {
  vis[s] = 1;
  for (__typeof((long long)adj[s].size()) x =
           (0) - ((0) > ((long long)adj[s].size()));
       x != ((long long)adj[s].size()) - ((0) > ((long long)adj[s].size()));
       x += 1 - 2 * ((0) > ((long long)adj[s].size()))) {
    long long i = adj[s][x];
    if (!vis[s]) dfs(i);
    for (__typeof((long long)adj[s].size()) y =
             (x + 1) - ((x + 1) > ((long long)adj[s].size()));
         y !=
         ((long long)adj[s].size()) - ((x + 1) > ((long long)adj[s].size()));
         y += 1 - 2 * ((x + 1) > ((long long)adj[s].size()))) {
      long long j = adj[s][y];
      if (!adj1[i][j]) continue;
      long long z = (long long)adj[s].size() + (long long)adj[i].size() +
                    (long long)adj[j].size() - 6;
      if (z < ans) ans = z;
    }
  }
}
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m))) {
    long long x, y;
    cin >> x >> y;
    adj[x].emplace_back(y);
    adj[y].emplace_back(x);
    adj1[x][y] = adj1[y][x] = 1;
  }
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1)))
    if (!vis[i]) dfs(i);
  if (ans == (unsigned long long)1e9)
    cout << (-1) << '\n';
  else
    cout << ans << '\n';
}
