#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long mod = 1e9 + 7;
const int oo = 1e9;
int n, m;
vector<vector<int> > g;
bool vis[N];
bool cycle = 0;
void DFS(int u, int p) {
  if (g[u].size() > 2) return;
  if (vis[u]) {
    cycle = true;
    return;
  }
  vis[u] = true;
  for (int i = 0; i < g[u].size(); ++i) {
    if (g[u][i] != p) DFS(g[u][i], u);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  g.clear();
  g.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cycle = 0;
    if (!vis[i] && g[i].size() <= 2) DFS(i, -1);
    if (cycle) ans++;
  }
  cout << ans;
}
