#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
int a[maxn];
int main() {
  int n, m, s, c;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s, &c);
    if (!a[s] || (a[s] && a[s] > c)) a[s] = c;
  }
  if (a[1] == 0) return puts("-1"), 0;
  for (int i = 1; i <= n; i++) printf("%d", a[i]);
  puts("");
  return 0;
}
