#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, m;
  string a, b;
  getline(cin, a);
  getline(cin, b);
  n = a.length();
  m = b.length();
  if ((n == m) && (a == b))
    cout << -1;
  else if ((n == m) && (a != b))
    cout << n;
  else if (n > m)
    cout << n;
  else if (m > n)
    cout << m;
  return 0;
}
