#include <bits/stdc++.h>
using namespace std;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
float Float() {
  float x;
  scanf("%f", &x);
  return x;
}
double Double() {
  double x;
  scanf("%lf", &x);
  return x;
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ' ';
  err(++it, args...);
}
const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const long long Mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long Inf = (long long)1e18;
typedef struct {
  int a, b;
} st;
bool cmp(st x, st y) {
  if (x.a != y.a) return x.a < y.a;
  return x.b <= y.b;
}
int main() {
  int test = 1, tc = 0;
  int n, m;
  while (test--) {
    n = Int();
    m = Int();
    st arr[m];
    for (int i = 0; i < m; i++) {
      arr[i].a = Int();
      arr[i].b = Int();
    }
    int s[n + 5];
    memset(s, false, sizeof s);
    for (int i = 0; i < m; i++) {
      if (s[arr[i].a] == 0) {
        s[arr[i].a] = arr[i].b;
      } else {
        if (s[arr[i].a] > arr[i].b) {
          s[arr[i].a] = arr[i].b;
        }
      }
    }
    if (s[1] == 0)
      printf("-1");
    else {
      for (int i = 1; i <= n; i++) {
        printf("%d", s[i]);
      }
    }
    printf("\n");
  }
  return 0;
}
