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