#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[200000], b[200000];
  cin >> a;
  cin >> b;
  long long int an, bn;
  an = strlen(a);
  bn = strlen(b);
  long long int i, j, k = 0;
  if (an != bn) {
    if (an > bn)
      cout << an;
    else
      cout << bn;
  } else {
    for (i = 0; i < an; i++) {
      if (a[i] != b[i]) {
        k = 1;
        break;
      }
    }
    if (k == 1)
      cout << an;
    else
      cout << "-1";
  }
  return 0;
}
