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