#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int main() {
  int n, m, s, c;
  int r[3] = {-1, -1, -1}, t;
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (r[s - 1] != -1 && r[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    r[s - 1] = c;
  }
  for (int a = 0; a < (10); ++a) {
    if (r[0] != -1) a = r[0];
    for (int b = 0; b < (10); ++b) {
      if (r[1] != -1) b = r[1];
      for (int c = 0; c < (10); ++c) {
        if (r[2] != -1) c = r[2];
        if (n == 1) {
          t = a;
        } else if (n == 2) {
          t = 10 * a + b;
        } else {
          t = 100 * a + 10 * b + c;
        }
        if (t >= (int)pow(10, n - 1)) {
          cout << t << endl;
          return 0;
        }
        if (r[2] != -1) break;
      }
      if (r[1] != -1) break;
    }
    if (r[0] != -1) break;
  }
  cout << -1 << endl;
  return 0;
}
