#include <bits/stdc++.h>
int main() {
  int flag[3] = {0};
  int n;
  int m;
  int num;
  int min_num;
  int a[2] = {0};
  num = 0;
  min_num = 0;
  while (scanf("%d %d", &n, &m) != EOF) {
    if (n == 3)
      if (flag[2] == 1) {
        if (num % 100 > m) num = num - num % 100 + m;
      } else {
        flag[2] = 1;
        num += m;
      }
    else if (n == 2)
      if (flag[1] == 1) {
        if (num / 10 % 10 > m) num = num - num / 10 % 10 * 10 + m * 10;
      } else {
        flag[1] = 1;
        num += m * 10;
      }
    else if (flag[0] == 1) {
      if (num / 100 > m) num = num - num / 100 * 10 + m * 10;
    } else {
      flag[0] = 1;
      num += m * 100;
    }
  }
  if (num > 0)
    printf("%d", num);
  else
    printf("-1");
  return 0;
}
