#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, k, cycles = 0, next, cur, last, temp;
  cin >> n >> m;
  vector<vector<long long int> > edges(n);
  vector<bool> visited(n, false);
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    edges[j - 1].push_back(k - 1);
    edges[k - 1].push_back(j - 1);
  }
  for (i = 0; i < n; i++) {
    if (!visited[i]) {
      visited[i] = true;
      if (edges[i].size() != 2) {
        continue;
      } else {
        next = edges[i][0];
        cur = i;
        last = edges[i][1];
        if (next == i || visited[next]) {
          continue;
        }
        while (next != i) {
          visited[next] = true;
          if (edges[next].size() != 2) {
            break;
          }
          temp = edges[next][0] + edges[next][1] - cur;
          cur = next;
          next = temp;
        }
        if (cur == last) {
          cycles++;
        }
      }
    }
  }
  cout << cycles;
  return 0;
}
