#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
const int N = (int)1e5 + 10;
void TimeExecution() {
  cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int n, m;
int s[10];
int c[10];
bool check(int i) {
  bool ok = 1;
  int tmp = i;
  string st;
  while (tmp) {
    st = char((tmp % 10) + '0') + st;
    tmp /= 10;
  }
  st = " " + st;
  for (int j = (1); j <= (m); j++) {
    if (st[s[j]] - '0' != c[j]) {
      ok = 0;
      break;
    }
  }
  return ok;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = (1); i <= (m); i++) {
    cin >> s[i] >> c[i];
  }
  if (n == 1) {
    for (int i = (0); i <= (9); i++) {
      if (check(i)) {
        cout << i;
        return 0;
      }
    }
  }
  if (n == 2) {
    for (int i = (10); i <= (99); i++) {
      if (check(i)) {
        cout << i;
        return 0;
      }
    }
  }
  if (n == 3) {
    for (int i = (100); i <= (999); i++) {
      if (check(i)) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
