#include <bits/stdc++.h>
int main() {
  char s[100005], n[100005];
  int ls, ln, i, j = 1, d;
  gets(s);
  gets(n);
  j = 1;
  ls = strlen(s);
  ln = strlen(n);
  if (ls == ln) {
    for (i = 0; i < ls; i++) {
      if (s[i] != n[i]) {
        j = 0;
        break;
      }
    }
  }
  if (ls == ln && j == 1) d = -1;
  if (ls > ln) d = ls;
  if (ln > ls) d = ln;
  if (ls == ln && j == 0) d = ls;
  printf("%d\n", d);
  return 0;
}
