#include <bits/stdc++.h>
using namespace std;
void solve() {
  string a, b;
  cin >> a;
  cin >> b;
  if (a == b)
    cout << -1;
  else {
    int al = a.length();
    int bl = b.length();
    cout << max(al, bl);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
