#include <bits/stdc++.h>
using namespace std;
bool visited[200005];
vector<int> v[200005];
bool dfs(int node) {
  int ans = 0;
  bool done = true;
  visited[node] = true;
  for (auto it : v[node]) {
    ans++;
    if (!visited[it]) {
      done = done & dfs(it);
    }
  }
  if (ans != 2) done = false;
  return done;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m, x, y;
  cin >> n >> m;
  int i, ans = 0;
  while (m--) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  fill(visited, visited + 200005, false);
  for (i = 1; i <= n; i++) {
    if (!visited[i]) {
      if (dfs(i)) ans++;
    }
  }
  cout << ans;
  return 0;
}
