#include <bits/stdc++.h>
int arr[100000] = {0};
using namespace std;
int main() {
  string s, x;
  cin >> s >> x;
  if (s == x) {
    cout << -1;
    return 0;
  }
  if (s.size() > x.size())
    cout << s.size();
  else
    cout << x.size();
  return 0;
}
