#include<bits/stdc++.h>
#define ll long long
#define ri register int
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a == b) cout<<a<<endl;
    else cout<<(3-a-b)<<endl;
    return 0;
}
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] != s.back()) {
    cout << "1\n";
    exit(0);
  } else {
    for (int i = 1; i + 1 < n - 1; ++i)
      if (s[i] != s[0] and s[i + 1] != s[0]) {
        cout << "2\n";
        exit(0);
      }
  }
  cout << "-1\n";
}
