#include <bits/stdc++.h>
using namespace std;
int main() {
  string x, y;
  cin >> x >> y;
  int t = 0;
  if (x.length() != y.length())
    t = 1;
  else {
    for (int i = 0; i < x.length(); i++) {
      if (x[i] != y[i]) {
        t = 1;
        goto ex;
      }
    }
  }
ex:
  if (t == 1)
    cout << max(x.length(), y.length());
  else
    cout << "-1";
  return 0;
}
