#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int c, d;
  cin >> a >> b;
  c = a.size();
  d = b.size();
  if (a == b && c == d)
    cout << "-1";
  else if (c == d)
    cout << c;
  else
    cout << max(c, d);
}
