#include<stdio.h>
#include<string.h>
#include<algorithm>
#include <vector>
#include <iostream>
using namespace std;
int arr[100010];
int size;
int pos[100010];
int val[100010];
int nums;
void dfs(int i,int x)
{
if(i < 0 || x <= 0) return;
while(pos[i] != x) i --;
dfs(i,x-1);
printf("%d\n",arr[i]);
}
int main()
{
int n;
size = 0;
memset(pos,0,sizeof(pos));
memset(val,0,sizeof(val));
while(scanf("%d",&n) != EOF)
{
arr[size++] = n;
}
nums = 1;
val[0] = arr[0];
pos[0] = 1;
for(int i=1;i<size;i++)
{
if(arr[i] > val[nums-1])
{
val[nums++] = arr[i];
pos[i] = nums;
}
else
{
int p = lower_bound(val,val+nums,arr[i]) - val;
val[p] = arr[i];
pos[i] = p+1;
}
}
printf("%d\n-\n",nums);
dfs(size-1,nums);
}