def next_smallest_palindrome(num):
    s = str(num)
    n = len(s)

    if all(ch == '9' for ch in s):
        return int('1' + '0' * (n - 1) + '1')

    half = n // 2
    if n % 2 == 0:
        left = s[:half]
        pal = left + left[::-1]
        if int(pal) > num:
            return int(pal)
        left_inc = str(int(left) + 1).zfill(half)
        if len(left_inc) > half:
            return int(left_inc + left_inc[:-1][::-1])
        return int(left_inc + left_inc[::-1])
    else:
        left = s[:half]
        mid = s[half]
        pal = left + mid + left[::-1]
        if int(pal) > num:
            return int(pal)
        prefix = str(int(left + mid) + 1).zfill(half + 1)
        if len(prefix) > half + 1:
            return int(prefix + prefix[:-2][::-1])
        return int(prefix + prefix[:-1][::-1])