#include <bits/stdc++.h>
bool dfs(int u, std::vector<std::vector<int>>& edges,
         std::vector<bool>& visited) {
  visited[u] = true;
  bool success = true;
  for (int v : edges[u]) {
    if (!visited[v] && !dfs(v, edges, visited)) {
      success = false;
    }
  }
  if (!success || edges[u].size() != 2) {
    return false;
  }
  return true;
}
int main() {
  int n, m, u, v;
  std::cin >> n >> m;
  std::vector<std::vector<int>> edges(n);
  std::vector<bool> visited(n);
  for (int i = 0; i < m; ++i) {
    std::cin >> u >> v;
    u -= 1;
    v -= 1;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  int answer = 0;
  for (int u = 0; u < n; ++u) {
    if (visited[u]) {
      continue;
    }
    if (dfs(u, edges, visited)) {
      answer += 1;
    }
  }
  std::cout << answer << std::endl;
  return 0;
}
