#include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    char c;
    
    int max = INT_MIN, m1 = -1, m2 = -1, res = 0;
    char cx = 'x';
    
    cin >> s;
    
    unordered_map<char, pair<int, int> > m;
    
    for (int i = 0; i < s.length(); ++i) {
        c = s[i];
        
        if (m.find(c) == m.end()) {
            m[c] = make_pair(i, -1);
        } else if (i > m[c].second) {
            m[c].second = i;
        }
        
        for (auto it = m.begin(); it != m.end(); ++it) {
            if (it->second.second - it->second.first >= max) {
                m1 = it->second.first;
                m2 = it->second.second;
                cx = it->first;
            }
        }
    }
    
    for (int i = m1 + 1; i < m2; ++i) {
        if (s[i] != cx) {
            ++res;
            s[i] = cx;
        }
    }
    
    cout << res;
}
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    string s;
    char c;
    
    int max = INT_MIN, m1 = -1, m2 = -1, res = 0;
    char cx = 'x';
    
    cin >> s;
    
    unordered_map<char, pair<int, int> > m;
    
    for (int i = 0; i < s.length(); ++i) {
        c = s[i];
        
        if (m.find(c) == m.end()) {
            m[c] = make_pair(i, -1);
        } else if (i > m[c].second) {
            m[c].second = i;
        }
        
        for (auto it = m.begin(); it != m.end(); ++it) {
            if (it->second.second - it->second.first >= max) {
                m1 = it->second.first;
                m2 = it->second.second;
                cx = it->first;
            }
        }
    }
    
    for (int i = m1 + 1; i < m2; ++i) {
        if (s[i] != cx) {
            ++res;
            s[i] = cx;
        }
    }
    
    cout << res;
}