#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
long long par[100005 * 2];
vector<int> v[100005 * 2];
long long c[100005 * 2];
long long union_find(int a) {
  if (par[a] == a) return a;
  return par[a] = union_find(par[a]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); i++) {
    par[i + 1] = i + 1;
  }
  int u, vv, a, b;
  for (int i = 0; i < (m); i++) {
    cin >> u >> vv;
    c[u]++;
    c[vv]++;
    a = union_find(u);
    b = union_find(vv);
    par[a] = b;
  }
  for (int i = 1; i <= n; i++) {
    if (c[i]) {
      a = union_find(i);
      v[a].push_back(i);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int sz = (int)(v[i]).size();
    if (sz && sz >= 3) {
      bool flg = 0;
      for (int j = 0; j < (sz); j++) {
        if (c[v[i][j]] != 2) {
          flg = 1;
          break;
        }
      }
      if (!flg) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
