#include <bits/stdc++.h>
using namespace std;
vector<long long> v[5000];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
long long graph[5000][5000] = {0};
long long dfs(long long s) {
  long long cnt, mn = INT_MAX;
  for (long long i = 0; i < v[s].size() - 1; i++) {
    for (long long j = i + 1; j < v[s].size(); j++) {
      if (graph[v[s][i]][v[s][j]] == 1) {
        cnt = v[v[s][i]].size() + v[s].size() + v[v[s][j]].size() - 6;
        mn = min(mn, cnt);
        cnt = 0;
      }
    }
  }
  return mn;
}
int main() {
  long long n, m, i, cnt = 0, j;
  cin >> n >> m;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    graph[x][y] = 1;
    graph[y][x] = 1;
  }
  for (i = 1; i <= n; i++) {
    q.push({v[i].size(), i});
    if (v[i].size() < 2) {
      cnt++;
    }
  }
  if (cnt == n) {
    cout << -1;
    return 0;
  }
  cnt = INT_MAX;
  i = 1;
  while (!q.empty()) {
    pair<long long, long long> p;
    p = q.top();
    i = p.second;
    j = p.first;
    q.pop();
    if (j >= 2) {
      cnt = min(cnt, dfs(i));
    }
  }
  if (cnt != INT_MAX) {
    cout << cnt;
  } else
    cout << -1;
  return 0;
}
