#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int MOD = 1e9 + 7;
const double PI = acos(-1);
const double e = 2.718281828459;
pair<int, int> p[10];
vector<int> v[10];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == 1 && y == 0) {
      continue;
    }
    v[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1 && v[i].size() == 0) {
      printf("-1");
      break;
    }
    if (v[i].size() == 0) {
      printf("0");
    } else {
      sort(v[i].begin(), v[i].end());
      printf("%d", v[i][0]);
    }
  }
  return 0;
}
