#include <bits/stdc++.h>
using namespace std;
vector<int> comp;
vector<int> graph[200005];
int vis[200005] = {0};
void bfs(int v) {
  vis[v] = 1;
  queue<int> q;
  q.push(v);
  while (!q.empty()) {
    int x = q.front();
    comp.push_back(x);
    q.pop();
    for (int i = 0; i < (int)graph[x].size(); i++) {
      if (!vis[graph[x][i]]) {
        vis[graph[x][i]] = 1;
        q.push(graph[x][i]);
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (!vis[i]) {
      comp.clear();
      bfs(i);
      int c = 0;
      for (int j = 0; j < (int)comp.size(); j++) {
        if ((int)graph[comp[j]].size() == 2)
          c = 1;
        else {
          c = 0;
          break;
        }
      }
      ans += c;
    }
  }
  cout << ans;
  return 0;
}
