#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using ld = long double;
const int MAXN = 200005;
int cha[MAXN], num[MAXN], edge[MAXN];
vector<vector<int>> g;
int n, m;
int ans = 0;
bitset<MAXN> f;
void init() {
  for (int i = 1; i <= n; ++i) {
    cha[i] = i;
    num[i] = 1;
    edge[i] = 0;
  }
}
int Find(int x) {
  if (cha[x] != x) cha[x] = Find(cha[x]);
  return cha[x];
}
void join(int x, int y) {
  int u = Find(x);
  int v = Find(y);
  if (u == v) {
    edge[u]++;
    return;
  }
  if (rand() & 1) swap(v, u);
  cha[v] = u;
  num[u] += num[v];
  edge[u] += edge[v] + 1;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m;
  init();
  g = vector<vector<int>>(n + 1);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    join(u, v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  f.reset();
  for (int i = 1; i <= n; ++i)
    if (cha[i] == i && edge[i] == num[i]) {
      queue<int> qu;
      bool flag = true;
      qu.push(i);
      while (!qu.empty()) {
        int u = qu.front();
        qu.pop();
        if (g[u].size() > 2) flag = false;
        f[u] = 1;
        for (int i = 0; i < g[u].size(); ++i)
          if (f[g[u][i]] == 0) {
            f[g[u][i]] = 1;
            qu.push(g[u][i]);
          }
      }
      if (flag) ans++;
    }
  cout << ans;
  return 0;
}
