#include <bits/stdc++.h>
using namespace std;

int N, M;

#define pii pair<int, int>
#define fi first
#define se second

vector<pii> v;
map<int, int> pos;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

	cin >> N >> M;

	for(int i = 0; i < M; i++){
		int a, b; cin >> a >> b;
		v.push_back({a, b});
	}

	sort(v.begin(), v.end());

	pos[N] = true;

	int prev = 0;

	vector<int> add, del;

	for(int i = 0; i < M; i++){
		if(v[i].fi != prev){
			for(auto& p : add) pos[p] = true;
			for(auto& p : del) pos[p] = false;
			prev = v[i].fi;
			add.clear(); del.clear();
		}

		int b = v[i].se;
		if(pos[b - 1] || pos[b + 1]) add.push_back(b);
		else del.push_back(b);
	}

	for(auto& p : add) pos[p] = true;
	for(auto& p : del) pos[p] = false;
	
	int sum = 0;

	for(auto& p : pos){
		if(p.se == 1) sum++;
	}

	cout << sum << '\n';
}
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

vvl G;
vl visited;
vvl S;  // S[v] : 頂点vに辿り着ける頂点集合

void dfs(ll sv, ll v) {
    // 行きの処理はこのへんに書く
    S[v].pb(sv);
    visited[v] = 1;
    for(ll u : G[v]) { 
        if(!visited[u]) {
            dfs(sv, u);
        }
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    ll n;
    cin >> n;

    G.resize(n);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if(s[j] == '1') {
                G[i].pb(j);
            }
        }
    }
    
    S.resize(n);
    rep(sv, n) {
        visited.assign(n, 0);
        dfs(sv, sv);
    }

    double ans = 0.0;
    rep(v, n) {
        ans += 1.0/(double)S[v].size();
    }

    exout(ans);
    re0;
}