import
java.io.*;
import
java.util.*;
public
class
GFG {
public
static
void
maxLength(
int
lis[],
int
n)
{
long
or =
0
;
for
(
int
i =
0
; i < n; i++) {
or |= lis[i];
}
int
[] count =
new
int
[
32
];
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j <
32
; j++) {
if
((lis[i] & (1L << j)) !=
0
)
count[j]++;
}
}
long
ans =
0
, l =
0
, tempOr =
0
;
for
(
int
r =
0
; r < n; r++) {
tempOr |= lis[r];
boolean
flag =
true
;
for
(
int
i =
0
; i <
32
; i++) {
if
((lis[r] & (1L << i)) !=
0
) {
count[i]--;
if
(count[i] ==
0
)
flag =
false
;
}
}
if
(!flag) {
for
(; l <= r;) {
boolean
flag1 =
true
;
for
(
int
i =
0
; i <
32
; i++) {
if
((lis[(
int
)l] & (1L << i))
!=
0
) {
count[i]++;
}
if
(count[i] ==
0
)
flag1 =
false
;
}
l++;
if
(flag1)
break
;
}
}
if
(tempOr == or) {
ans = Math.max(ans, r - l +
1
);
}
}
if
(ans !=
0
)
System.out.println(ans);
else
System.out.println(-
1
);
}
public
static
void
main(String[] args)
{
String S =
"2347"
;
int
N = S.length();
int
[] A =
new
int
[N];
for
(
int
i =
0
; i < N; i++) {
A[i] = S.charAt(i) -
'0'
;
}
maxLength(A, N);
}
}