#include <bits/stdc++.h>
using namespace std;
bool already_visited[200005];
vector<int> adjacency_list[200005];
vector<int> current_connected_compoent;
void dfs(int current_node) {
  already_visited[current_node] = true;
  current_connected_compoent.push_back(current_node);
  for (auto option : adjacency_list[current_node]) {
    if (already_visited[option]) {
      continue;
    } else {
      dfs(option);
    }
  }
}
int n, m;
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adjacency_list[u].push_back(v);
    adjacency_list[v].push_back(u);
  }
  int answer = 0;
  for (int node = 1; node <= n; node++) {
    if (!already_visited[node]) {
      current_connected_compoent.clear();
      dfs(node);
      bool is_cycle = true;
      for (auto node : current_connected_compoent) {
        int degree = (int)adjacency_list[node].size();
        if (degree != 2) is_cycle = false;
      }
      if (is_cycle) {
        answer++;
      }
    }
  }
  cout << answer << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
