#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const long long INF = 1ll << 60;
int n, m;
bool flg[25];
int ans;
struct PP {
  int s, c;
} p[25];
bool cmp(PP x, PP y) {
  if (x.s == y.s) return x.c < y.c;
  return x.s < y.s;
}
void Init() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &p[i].s, &p[i].c);
    flg[p[i].s] = 1;
  }
}
int cnt(int x) {
  int res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
int main() {
  Init();
  sort(p + 1, p + m + 1, cmp);
  int num = 1;
  for (int i = 2; i <= n; i++) num *= 10;
  for (int i = 1; i <= n; i++) {
    if (flg[i]) ans += num * p[i].c;
    num /= 10;
  }
  if (ans < 0 || cnt(ans) != n)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
