#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> G(300005);
int vis[300005] = {0}, flag = 0;
void dfs(int i, int par) {
  vis[i] = 1;
  if (G[i].size() != 2) flag = 1;
  int j;
  for (j = 0; j < G[i].size(); j++) {
    int ch = G[i][j];
    if (vis[ch] == 0) {
      dfs(ch, i);
    }
  }
  return;
}
int main() {
  int n, m, i, x, y, cnt = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    G[x].push_back({y}), G[y].push_back({x});
  }
  for (i = 1; i <= n; i++) {
    flag = 0;
    if (vis[i] == 0) {
      dfs(i, -1);
      if (flag == 0) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
