#include <bits/stdc++.h>
using _loop_int = int;
using namespace std;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
int main() {
  int N, M;
  cin >> N >> M;
  int ans[N], s, c;
  for (_loop_int i = 0; i < (_loop_int)(3); i++) {
    ans[i] = 10;
  }
  for (_loop_int i = 0; i < (_loop_int)(M); i++) {
    cin >> s >> c;
    if (ans[N - s] > 9) {
      ans[N - s] = c;
    } else if (ans[N - s] < 10 & ans[N - s] != c) {
      ans[N - s] = -1;
    }
  }
  int b = 0;
  for (_loop_int i = 0; i < (_loop_int)(N); i++) {
    if (ans[i] < 0) {
      b = -1;
      break;
    } else if (ans[i] == 0) {
      if (i == 0 & N != 1) {
        b = -1;
        break;
      }
    } else if (ans[i] < 10) {
      b += int(pow(10, i)) * ans[i];
    } else {
      if (i == N - 1) {
        b += int(pow(10, N - 1));
      }
    }
  }
  if (N == 3) {
    if (b < 100) {
      b = -1;
    }
  } else if (N == 2) {
    if (b < 10 || 99 < b) {
      b = -1;
    }
  } else {
    if (b > 10) {
      b = -1;
    }
  }
  cout << b << endl;
  return 0;
}
