#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool flag = true;
  int n, m;
  cin >> n >> m;
  int ary[n];
  for (int i = (int)(0); i < (int)(n); ++i) ary[i] = -1;
  for (int i = (int)(0); i < (int)(m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s >= n) {
      flag = false;
      break;
    }
    if (ary[s] != -1 && ary[s] != c) {
      flag = false;
      break;
    }
    ary[s] = c;
  }
  if (ary[0] == 0) {
    flag = false;
  }
  for (int i = (int)(0); i < (int)(n); ++i)
    if (ary[i] == -1) ary[i] = 0;
  bool zero = 0;
  if (flag) {
    for (int i = (int)(0); i < (int)(n); ++i) {
      if (zero == 0 && ary[i] == 0) {
      } else {
        cout << ary[i];
        zero = 1;
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
