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