#include <bits/stdc++.h>
using namespace std;
int rec[4002], n, m, mn = 1000000, a, b;
vector<int> v[4002];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    rec[a]++;
    rec[b]++;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int p, q, c = 0;
  for (int i = 1; i <= n; i++) {
    if (rec[i] >= 2) {
      for (int j = 0; j < v[i].size(); j++) {
        p = v[i][j];
        if (rec[p] >= 2) {
          for (int k = 0; k < v[p].size(); k++) {
            q = v[p][k];
            if (q != i) {
              for (int m = 0; m < v[q].size(); m++) {
                if (v[q][m] == i) {
                  mn = min(mn, rec[i] + rec[p] + rec[q] - 6);
                }
              }
            }
          }
        }
      }
    }
  }
  if (mn == 1000000) mn = -1;
  cout << mn;
}
