#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8 + 1;
vector<vector<int> > adj;
vector<bool> visited;
bool flag;
void DFS(int nodo) {
  visited[nodo] = true;
  if (adj[nodo].size() != 2) {
    flag = false;
  }
  for (auto it : adj[nodo]) {
    if (!visited[it]) DFS(it);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  adj.resize(n + 1);
  visited.resize(n + 1, false);
  for (int i = 0; i < m; i++) {
    int d, h;
    cin >> d >> h;
    adj[d].push_back(h);
    adj[h].push_back(d);
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (!visited[i]) {
      flag = true;
      DFS(i);
      if (flag) ans++;
    }
  }
  cout << ans;
}
