#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, s[100], c[100], i, ans = 0, f = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  if (n == 1) {
    for (ans = 0; ans <= 9; ans++) {
      for (i = 0; i < m; i++) {
        if (ans == c[i]) f++;
      }
      if (f == m) {
        cout << ans << endl;
        return 0;
      }
      f = 0;
    }
    cout << -1 << endl;
    return 0;
  }
  if (n == 2) {
    for (ans = 10; ans <= 99; ans++) {
      for (i = 0; i < m; i++) {
        if (s[i] == 1) {
          if ((ans / 10) == c[i]) f++;
        } else if (s[i] == 2) {
          if ((ans % 10) == c[i]) f++;
        }
      }
      if (f == m) {
        cout << ans << endl;
        return 0;
      }
      f = 0;
    }
    cout << -1 << endl;
    return 0;
  }
  if (n == 3) {
    for (ans = 100; ans <= 999; ans++) {
      for (i = 0; i < m; i++) {
        if (s[i] == 1) {
          if ((ans / 100) == c[i]) f++;
        } else if (s[i] == 2) {
          int tmp = ans;
          tmp = ans / 10;
          tmp = ans % 10;
          if (tmp == c[i]) f++;
        } else if (s[i] == 3) {
          if ((ans % 10) == c[i]) f++;
        }
      }
      if (f == m) {
        cout << ans << endl;
        return 0;
      }
      f = 0;
    }
    cout << -1 << endl;
    return 0;
  }
  return 0;
}
