#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool fs(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
int parent[200005];
int mark[200005];
void initializeSet(int n) {
  for (int i = 1; i <= n; i++) parent[i] = i;
}
int findParent(int x) {
  if (x == parent[x])
    return x;
  else
    return parent[x] = findParent(parent[x]);
}
int unionSet(int x, int y) {
  int px = findParent(x);
  int py = findParent(y);
  if (px == py)
    return 1;
  else
    parent[py] = px;
  return 0;
}
int main() {
  int n, m, cnt = 0, a, b;
  vector<pair<int, int> > v;
  cin >> n >> m;
  initializeSet(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    mark[a]++;
    mark[b]++;
    v.push_back(make_pair(a, b));
  }
  for (int i = 0; i < m; i++) {
    a = v[i].first;
    b = v[i].second;
    if (mark[a] == 2 && mark[b] == 2) cnt += unionSet(a, b);
  }
  cout << cnt << endl;
  return 0;
}
