#include <bits/stdc++.h>
struct vertex_entry {
  int component = -1;
  std::vector<int> edges;
};
std::vector<vertex_entry> vertices;
bool paint(int vertex, int component) {
  auto& v = vertices[vertex];
  assert(v.component < 0);
  v.component = component;
  std::stack<int> reachable_vertices;
  reachable_vertices.push(vertex);
  bool is_cycle = true;
  while (reachable_vertices.size()) {
    auto vertex = reachable_vertices.top();
    reachable_vertices.pop();
    auto& v = vertices[vertex];
    assert(v.component == component);
    if (v.edges.size() != 2) {
      is_cycle = false;
    }
    for (auto adj : v.edges) {
      auto& u = vertices[adj];
      assert(u.component == -1 || u.component == component);
      if (u.component < 0) {
        u.component = component;
        reachable_vertices.push(adj);
      }
    }
  }
  return is_cycle;
}
int main() {
  int n, m;
  std::cin >> n >> m;
  vertices.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    vertices[u].edges.push_back(v);
    vertices[v].edges.push_back(u);
  }
  int component = 0;
  int cycles = 0;
  for (int i = 1; i < n; ++i) {
    if (vertices[i].component == -1) {
      bool cycle = paint(i, component++);
      if (cycle) {
        ++cycles;
      }
    }
  }
  std::cout << cycles << '\n';
}
