// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

struct atsu {int cnt; char c;};

int main() {
    string s;
    cin >> s;

    vector<atsu> v;
    int cnt = 0;
    char pre = ' ';
    rep(i, s.size()) {
        if (s[i]==pre) cnt++;
        else {
            v.push_back((atsu){cnt, pre});
            cnt = 1;
            pre = s[i];
        }
    }
    v.push_back((atsu){cnt, pre});

    int ans;
    if (v[0].c != '?') ans = v[0].cnt;
    for (int i=1; i<(int)v.size(); i++) {
        if (i+1==(int)v.size() && v[i].c=='?') break;
        if (v[i].c != '?') ans = max(ans, v[i].cnt);
        else if (v[i-1].c == v[i+1].c) {
            if (v[i].cnt < v[i-1].cnt && v[i].cnt < v[i+1]) v[i+1].cnt += v[i-1].cnt - v[i].cnt;
            if (v[i].cnt %2 == 0) ans = max(ans, 2);
        }
    }

    cout << ans << endl;

    return 0;
}