#include <bits/stdc++.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = (1 << 30);
int main() {
  int n, m, s[10], c[10];
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  string str;
  bool flag = 0;
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      str = to_string(i);
      for (int j = 0; j < m; j++) {
        if (str[s[j] - 1] != c[j] + '0') {
          flag = 0;
          break;
        } else
          flag = 1;
      }
      if (flag) {
        cout << str << endl;
        return 0;
      }
    }
  } else if (n == 2) {
    for (int i = 10; i < 100; i++) {
      str = to_string(i);
      for (int j = 0; j < m; j++) {
        if (str[s[j] - 1] != c[j] + '0') {
          flag = 0;
          break;
        } else
          flag = 1;
      }
      if (flag) {
        cout << str << endl;
        return 0;
      }
    }
  } else {
    for (int i = 100; i < 1000; i++) {
      str = to_string(i);
      for (int j = 0; j < m; j++) {
        if (str[s[j] - 1] != c[j] + '0') {
          flag = 0;
          break;
        } else
          flag = 1;
      }
      if (flag) {
        cout << str << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
