#include <bits/stdc++.h>
using namespace std;
int main() {
  int j, pos = 0, cnt;
  string a, b;
  cin >> a >> b;
  cnt = max(a.size(), b.size());
  if (a == b) {
    cout << -1;
    return 0;
  }
  cout << cnt;
}
