#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int ac = a.size();
  int bc = b.size();
  int c = a.compare(b);
  if (c == 0) {
    cout << -1;
    return 0;
  }
  if (ac > bc)
    cout << ac;
  else
    cout << bc;
  return 0;
}
