#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  string s, s1;
  cin >> s >> s1;
  if (s != s1)
    cout << max(s1.length(), s.length());
  else
    cout << -1;
  return 0;
}
