#include <bits/stdc++.h>
using namespace std;
const int Max = 2 * 1e6 + 100;
vector<int> adj[Max];
bool visit[Max];
bool cycle;
int cnt;
int start[Max];
int c;
int vertex, e;
set<int> edges;
void DFS(int u) {
  visit[u] = 1;
  start[u] = c++;
  vertex++;
  e += adj[u].size();
  edges.insert(adj[u].size());
  for (auto v : adj[u]) {
    if (!visit[v]) {
      DFS(v);
    } else {
      if (start[v] > start[u] && adj[u].size() != 1) {
        cycle = 1;
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!visit[i]) {
      DFS(i);
      if (edges.size() == 1 && e / 2 == vertex && cycle) {
        cnt++;
      }
      edges.clear();
      vertex = 0;
      cycle = 0;
      e = 0;
    }
  }
  printf("%d", cnt);
  return 0;
}
