#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
long long int mod = 1e9 + 7;
int ans = 0;
int a[3] = {-1, -1, -1};
int n, m;
int M = 0;
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s = 4 - s;
    M = max(M, s);
    s--;
    if (a[s] == -1) {
      a[s] = c;
    } else if (a[s] != 1e9 + 7 && a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (M > n) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    for (int i = 0; i <= 9; i++) {
      bool key = true;
      int tmp = i;
      for (int j = 0; j < n; j++) {
        if (a[j] != -1 && a[j] != tmp % 10) {
          key = false;
          break;
        }
        tmp = tmp / 10;
      }
      if (key) {
        cout << i << endl;
        return 0;
      }
    }
  } else if (n == 2) {
    if (a[n - 1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 10; i <= 99; i++) {
      bool key = true;
      int tmp = i;
      for (int j = 0; j < n; j++) {
        if (a[j] != -1 && a[j] != tmp % 10) {
          key = false;
          break;
        }
        tmp = tmp / 10;
      }
      if (key) {
        cout << i << endl;
        return 0;
      }
    }
  } else {
    if (a[n - 1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 100; i <= 999; i++) {
      bool key = true;
      int tmp = i;
      for (int j = 0; j < n; j++) {
        if (a[j] != -1 && a[j] != tmp % 10) {
          key = false;
          break;
        }
        tmp = tmp / 10;
      }
      if (key) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
