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