#include <bits/stdc++.h>
using namespace std;
int n, m, i;
int num = 0, ans = 0;
bool ok = true;
vector<int> graph[200003];
bool visit[200003] = {false};
void dfs(int node) {
  visit[node] = true;
  if (graph[node].size() != 2) ok = false;
  for (int h = 0; h < graph[node].size(); h++) {
    int child = graph[node][h];
    if (!visit[child]) dfs(child), num++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    graph[from].push_back(to);
    graph[to].push_back(from);
  }
  for (int i = 1; i <= n; i++) {
    num = 1;
    ok = true;
    if (!visit[i]) {
      dfs(i);
      if (num > 2 && ok) ans++;
    }
  }
  cout << ans;
  return 0;
}
