#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  string a, b;
  cin >> a >> b;
  if (a == b)
    cout << "-1\n";
  else
    cout << max(a.size(), b.size()) << '\n';
  return 0;
}
