#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int INF = 1000000000;
const long long LINF = 100000000000000000;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
const long long MOD = 1000000007;
const int MAX = 1200000;
struct edge {
  long long to;
  long long cost;
};
struct UnionFind {
  vector<int> UF;
  vector<int> SIZE;
  UnionFind(int N) : UF(N), SIZE(N, 1) {
    for (int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) {
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) {
      return;
    }
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    } else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return SIZE.at(root(x)); }
};
int ctoi(char c) {
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5;
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;
}
char to_char(int i) {
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8';
  if (i == 9) return '9';
  return ' ';
}
int main() {
  cout << fixed << setprecision(16);
  int N, M;
  cin >> N >> M;
  string A = "";
  for (int i = 0; i < N; i++) {
    A += '%';
  }
  bool ok = true;
  for (int i = 0; i < M; i++) {
    int S, C;
    cin >> S >> C;
    if (A.at(S - 1) != '%' && A.at(S - 1) != to_char(C)) {
      ok = false;
    }
    A.at(S - 1) = to_char(C);
  }
  if (ok) {
    ok = true;
    for (int i = 0; i < N; i++) {
      if (A.at(i) == '%') {
        if (ok) {
          continue;
        } else {
          cout << 0;
        }
      } else {
        ok = false;
        cout << A.at(i);
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
