#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string t;
  cin >> s;
  cin >> t;
  int suma = 1;
  int sumb = 1;
  if (operator==(s, t)) {
    cout << -1;
  } else if (s.length() >= t.length()) {
    cout << s.length();
  } else if (s.length() < t.length()) {
    cout << t.length();
  }
  return 0;
}
