#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 2e5 + 10;
vector<int> G[MAX_V];
int n, m, flag;
bool visit[MAX_V];
void dfs(int index) {
  visit[index] = 1;
  if (G[index].size() != 2) flag = 0;
  for (auto i : G[index])
    if (!visit[i]) dfs(i);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  int a, b;
  while (m--) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    flag = 1;
    if (!visit[i]) {
      dfs(i);
      if (flag) ans++;
    }
  }
  cout << ans << endl;
}
