#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; ++i) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < M; ++i) s[i]--;
  vector<pair<int, int> > p(M);
  for (int i = 0; i < M; ++i) {
    p[i] = make_pair(s[i], c[i]);
  }
  sort(p.begin(), p.end());
  int d[N];
  for (int i = 0; i < N; ++i) d[i] = -1;
  for (int i = 0; i < M; ++i) {
    if (i > 0) {
      if (p[i].first == p[i - 1].first) {
        if (p[i].second != p[i - 1].second) {
          cout << -1;
          return 0;
        }
      }
    }
    d[p[i].first] = p[i].second;
  }
  if (d[0] <= 0 && d[1] <= -1 && d[2] <= -1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < N; ++i) {
    if (d[i] > 0)
      cout << d[i];
    else
      cout << 0;
  }
  return 0;
}
