#include <bits/stdc++.h>
using namespace std;
long long sum[400500];
int a[100500];
int b[100500];
int c[100500];
void build(int v, int l, int r) {
  int m;
  if (l == r) {
    sum[v] = a[l];
    return;
  }
  m = (r + l) / 2;
  build(2 * v, l, m);
  build(2 * v + 1, m + 1, r);
  sum[v] = sum[2 * v] + sum[2 * v + 1];
}
int find(int v, int l, int r, int x, int y) {
  int m;
  if (l == r) return sum[l];
  m = (r + l) / 2;
  if (y <= m) return find(v * 2, l, m, x, y);
  if (x > m) return find((2 * v + 1), m + 1, r, x, y);
  return (find(v * 2, l, m, x, y) + find((2 * v + 1), m + 1, r, x, y));
}
int main() {
#pragma warning(disable : 4996)
  int n, i, x, y, z, m, t;
  string s1, s2;
  getline(cin, s1);
  getline(cin, s2);
  if (s2 != s1)
    cout << max(s1.length(), s2.length());
  else
    cout << -1;
  return 0;
}
