[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
create constant integer maxn with maxn = 2e5 + 10
create integers n, m
create string array s with size 110
create 2d integer array l with size 110 by 10010
create 2d integer array r with size 110 by 10010
define the main function
    read n read m
    for i = 0 to n exclusive, read s[i]
    create boolean bad with bad = false
    for i = 0 to n exclusive
        create integer last with last = -1
        for j = 0 to m exclusive
            if s[i][j] is '0'
                set l[i][j] to -1 if last is -1, else j - last
            else
                set l[i][j] to 0, set last to j
        if last is less than 0, set bad to true
        set last to -1
        for j = m - 1 to 0 inclusive, decrementing j
            if s[i][j] is '0'
                set r[i][j] to -1 if last is -1, else last - j
            else
                set r[i][j] to 0, set last to j
        for j = 0 to m exclusive
            if l[i][j] is less than 0, set l[i][j] to j + l[i][m-1] + 1
        for j = m - 1 to 0 inclusive, decrementing j
            if r[i][j] is less than 0, set r[i][j] to (m - 1) - j + r[i][0] + 1
    end of the block
    if bad is true
        print -1 print "\n"
        return to indicate successful execution
    end of the block
    create long long ans with ans = n * m + 1
    for j = 0 to m exclusive
        create long long cur with cur = 0
        for i = 0 to n exclusive, increment cur by minimum of l[i][j] and r[i][j]
        set ans to minimum of ans and cur
    end of the block
    print ans print "\n"
end of the block

[CODE]:

const int maxn = 2e5 + 10;
int n, m;
string s[110];
int l[110][10010];
int r[110][10010];
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> s[i];
    bool bad = false;
    for (int i = 0; i < n; ++i) {
        int last = -1;
        for (int j = 0; j < m; ++j)
            if (s[i][j] == '0')
                l[i][j] = (last == -1 ? -1 : j - last);
            else
                l[i][j] = 0, last = j;
        if (last < 0) bad = true;
        last = -1;
        for (int j = m - 1; j >= 0; --j)
            if (s[i][j] == '0')
                r[i][j] = (last == -1 ? -1 : last - j);
            else
                r[i][j] = 0, last = j;
        for (int j = 0; j < m; ++j)
            if (l[i][j] < 0) l[i][j] = j + l[i][m - 1] + 1;
        for (int j = m - 1; j >= 0; --j)
            if (r[i][j] < 0) r[i][j] = (m - 1) - j + r[i][0] + 1;
    }
    if (bad) {
        cout << -1 << "\n";
        return 0;
    }
    long long ans = n * m + 1;
    for (int j = 0; j < m; ++j) {
        long long cur = 0;
        for (int i = 0; i < n; ++i) cur += min(l[i][j], r[i][j]);
        ans = min(ans, cur);
    }
    cout << ans << "\n";
}