#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  cin >> s >> s1;
  if (s == s1) {
    cout << -1 << endl;
    return 0;
  }
  cout << max(s.length(), s1.length()) << endl;
}
