#include <bits/stdc++.h>
using namespace std;
long long int ans = 0;
long long int parent[200001] = {0}, size[200001] = {0};
bool b = 0;
void eg(vector<long long int> adj[], long long int u, long long int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
long long int fp(long long int i) {
  if (parent[parent[i]] != parent[i]) parent[i] = fp(parent[i]);
  return parent[i];
}
void dfsu(long long int u, vector<long long int> adj[], vector<bool> &vis,
          long long int k) {
  vis[u] = 1;
  if (adj[u].size() != 2) {
    b = 0;
    return;
  }
  if (k != size[fp(u)] && k != 2) {
    if (adj[u][0] == fp(u) || adj[u][1] == fp(u)) {
      b = 0;
      return;
    }
  }
  if (k == size[fp(u)]) {
    if (adj[u][0] != fp(u) && adj[u][1] != fp(u)) {
      b = 0;
      return;
    }
  }
  for (long long int i = 0; i < adj[u].size(); i++) {
    if (vis[adj[u][i]] == false) dfsu(adj[u][i], adj, vis, k + 1);
  }
}
void un(long long int a, long long int b) {
  long long int parent_a = fp(a), parent_b = fp(b);
  if (parent_a == parent_b) return;
  if (size[parent_a] >= size[parent_b]) {
    size[parent_a] += size[parent_b];
    parent[parent_b] = parent_a;
  } else {
    size[parent_b] += size[parent_a];
    parent[parent_a] = parent_b;
  }
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> adj[n + 1];
  vector<bool> vis(n + 1, 0);
  ans = 0;
  for (long long int i = 1; i <= n; i++) {
    parent[i] = i;
    size[i] = 1;
  }
  for (long long int i = 0; i < m; i++) {
    long long int u, v;
    cin >> u >> v;
    eg(adj, u, v);
    un(u, v);
  }
  for (long long int i = 1; i <= n; i++) {
    if (fp(i) == i) {
      b = 1;
      if (size[i] < 3)
        b = 0;
      else {
        dfsu(i, adj, vis, 1);
      }
      if (b == 1) ans++;
    }
  }
  cout << ans;
}
