#include <bits/stdc++.h>
using namespace std;
vector<int> v[200002];
int vis[200002], nrCC, flag;
void DFS(int x) {
  vis[x] = 1;
  if (v[x].size() != 2) {
    flag = 0;
  }
  for (int i = 0; i < v[x].size(); ++i)
    if (!vis[v[x][i]]) DFS(v[x][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int x, y, i = 1; i <= m; ++i) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      flag = 1;
      DFS(i);
      nrCC += flag;
    }
  cout << nrCC << "\n";
  return 0;
}
