#include <bits/stdc++.h>
using namespace std;
string S1, S2;
int main() {
  cin >> S1 >> S2;
  if (S1.size() < S2.size())
    cout << S2.size() << "\n";
  else if (S1.size() > S2.size())
    cout << S1.size() << "\n";
  else if (S1 == S2)
    cout << "-1\n";
  else
    cout << S1.size() << "\n";
  return 0;
}
