#include <bits/stdc++.h>
using namespace std;
int N, E, val, x, y;
bool visited[200005], cek = 1;
vector<int> adj[200005];
void dfs(int x) {
  visited[x] = 1;
  if (adj[x].size() != 2) {
    cek = 0;
  }
  for (int i = 0; i < adj[x].size(); i++) {
    int nb = adj[x][i];
    if (!visited[nb]) dfs(nb);
  }
}
int main() {
  cin >> N >> E;
  for (int i = 1; i <= E; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (int i = 1; i <= N; i++) {
    if (!visited[i]) {
      cek = 1;
      dfs(i);
      if (cek == 1) val++;
    }
  }
  cout << val << endl;
}
