#include <bits/stdc++.h>
using namespace std;
int num_cycle = 0;
int beg_cycle = -1;
int end_cycle = -1;
set<int> to_visit;
int ne = 0;
bool c = false;
bool nl = false;
void dfs(vector<vector<int>> &v, set<int> &allv, int currv) {
  end_cycle = currv;
  if (v[currv].size() != 2) nl = true;
  for (int i = 0; i < v[currv].size(); i++) {
    ne++;
    if (allv.count(v[currv][i])) {
      allv.erase(v[currv][i]);
      dfs(v, allv, v[currv][i]);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << "\n";
    return 0;
  }
  vector<vector<int>> v(n + 1);
  set<int> allv;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    allv.insert(a);
    allv.insert(b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  while (allv.size()) {
    nl = false;
    ne = 0;
    int cv = allv.size();
    int begv = *(allv.begin());
    beg_cycle = begv;
    to_visit.clear();
    allv.erase(begv);
    dfs(v, allv, begv);
    int chg = cv - allv.size();
    if (!nl && chg > 2 && ((chg * 2) == ne)) {
      bool chk = false;
      for (int xi = 0; xi < v[end_cycle].size(); xi++) {
        if (v[end_cycle][xi] == beg_cycle) {
          chk = true;
          break;
        }
      }
      if (chk) num_cycle++;
    }
    ne = 0;
    nl = false;
  }
  cout << num_cycle << "\n";
}
