#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b;
  cin >> a >> b;
  bool f{false};
  int la = a.size(), lb = b.size(), ct = 0;
  int j = 0, mx = 0;
  if (a == b)
    cout << -1;
  else
    cout << max(la, lb);
  return 0;
  ;
}
