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