#include <bits/stdc++.h>
using namespace std;
int r = 0, c = 0, xd = 0, yd = 0;
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int flag = 0;
int n = 0, m = 0;
vector<int> v[4005];
int visited[4005];
int pr[4005];
int ans = 1000000007;
int con[4005][4005];
void dfs(int root) {
  visited[root] = 1;
  for (int i = 0; i < v[root].size(); i++) {
    int ele = v[root][i];
    if (!visited[ele]) {
      pr[ele] = root;
      dfs(ele);
    } else {
      int pr_root = pr[root];
      while (pr_root != -1) {
        if (con[pr_root][root] == 1 && con[pr_root][ele] == 1) {
          int sz1 = v[root].size();
          int sz2 = v[ele].size();
          int sz3 = v[pr_root].size();
          int h = sz1 + sz2 + sz3 - 6;
          ans = min(ans, h);
        }
        pr_root = pr[pr_root];
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  int t1;
  int t2;
  vector<int> o;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &t1, &t2);
    o.push_back(t1);
    o.push_back(t2);
    v[t1].push_back(t2);
    v[t2].push_back(t1);
    con[t1][t2] = 1;
    con[t2][t1] = 1;
  }
  for (int i = 0; i < o.size(); i++) {
    int g = o[i];
    pr[g] = -1;
    if (!visited[g]) dfs(g);
  }
  if (ans == 1000000007) ans = -1;
  cout << ans << endl;
  return 0;
}
