class Solution { public: int res = INT_MAX; int n; int count = 0; void dfs(vector<int> &nums, vector<bool> &flag, int index) { if (index == n-1) { res = min(res, count); } count++; flag[index] = true; if (index > 0 ) { if (!flag[index - 1]) { dfs(nums, flag, index - 1); } } if (!flag[index + 1]) { dfs(nums, flag, index + 1); } for (int i = 0; i < nums.size(); ++i) { if (nums[i] == nums[index] && !flag[i]) { dfs(nums, flag, i); } } count--; flag[index] = false; } void Func() { vector<int> nums; string str; getline(cin, str); str = str.substr(1, str.size() - 2); stringstream ss(str); string tmp; while (getline(ss, tmp, ',')) { nums.push_back(stoi(tmp)); } n = nums.size(); vector<bool> flag(n, false); dfs(nums, flag, 0); cout << res << endl; } }; int main() { Solution temp; temp.Func(); }