#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[26] = {};
  int b[26] = {};
  string m, e;
  cin >> m >> e;
  if (m.length() != e.length()) {
    cout << max(m.length(), e.length()) << endl;
    return 0;
  }
  if (m != e)
    cout << m.length() << endl;
  else
    cout << "-1" << endl;
}
