#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1;
  string s2;
  cin >> s1;
  cin >> s2;
  if (s1.length() > s2.length()) {
    cout << s1.length();
  } else if (s1 != s2) {
    cout << s2.length();
  } else {
    cout << "-1";
  }
  return 0;
}
