#include <bits/stdc++.h>
using namespace std;
int a1[100];
int fin = 0;
int m = 1;
string a, b;
int main() {
  cin >> a >> b;
  if (a != b) {
    cout << max(a.size(), b.size());
    return 0;
  }
  cout << -1;
}
