#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[6], c[6], ans;
  bool bb, cc;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int u = 0; u < 1000; u++) {
    if (n == 1 && u > 9)
      continue;
    else if (pow(10, n - 1) > u && u >= pow(10, n))
      continue;
    cc = true;
    for (int i = 0; i < m; i++) {
      bb = false;
      if (n == 3) {
        if (s[i] == 1 && u / 100 == c[i] && c[i] != 0)
          bb = true;
        else if (s[i] == 2 && (u % 100) / 10 == c[i])
          bb = true;
        else if (s[i] == 3 && u % 10 == c[i])
          bb = true;
      } else if (n == 2) {
        if (s[i] == 1 && (u % 100) / 10 == c[i] && c[i] != 0)
          bb = true;
        else if (s[i] == 2 && u % 10 == c[i])
          bb = true;
      } else {
        if (s[i] == 1 && u % 10 == c[i]) bb = true;
      }
      if (bb == false) {
        cc = false;
        break;
      }
    }
    if (cc == false && u < 999)
      continue;
    else if (cc) {
      ans = u;
      break;
    } else if (u == 999)
      ans = -1;
  }
  cout << ans << endl;
  return 0;
}
