#include <bits/stdc++.h>
using namespace std;
int main() {
  char arr1[100009];
  char arr2[100009];
  scanf("%s%s", arr1, arr2);
  if (strcmp(arr1, arr2) != 0) {
    cout << max(strlen(arr1), strlen(arr2));
  } else {
    cout << -1 << endl;
  }
}
