#include <bits/stdc++.h>
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int b[n];
  for (int i = 0; i < (n); i++) {
    a[i] = 0;
    b[i] = 0;
  }
  int flag = 1;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (c == 0) {
      if (a[s - 1] == 0) {
        b[s - 1]++;
        continue;
      } else {
        flag = 0;
        b[s - 1]++;
      }
    } else if (c != 0) {
      if (a[s - 1] == 0) {
        if (b[s - 1] != 0) {
          flag = 0;
          b[s - 1]++;
        } else {
          a[s - 1] = c;
          b[s - 1]++;
        }
      } else if (a[s - 1] != 0) {
        if (a[s - 1] == c) {
          b[s - 1]++;
          continue;
        } else {
          flag = 0;
          b[s - 1]++;
        }
      }
    }
  }
  if (flag == 0) cout << "-1";
  if (a[0] == 0 && flag == 1) {
    if (n != 1) {
      cout << "-1";
      flag = 0;
    }
  }
  if (flag == 1) {
    for (int i = 0; i < (n); i++) {
      cout << a[i];
    }
  }
  return 0;
}
