#include <bits/stdc++.h>
using namespace std;
int ctoi(const char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return -1;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int mini = 10000000;
  int flag = 1;
  int beg = 1;
  for (int i = 0; i < n - 1; i++) beg *= 10;
  int end = beg * 10 - 1;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = beg; i <= end; i++) {
    string str = to_string(i);
    flag = 1;
    for (int j = 0; j < m; j++) {
      if (ctoi(str[(s[j]) - 1]) != c[j]) {
        flag = 0;
      }
    }
    if (flag == 1) {
      mini = min(mini, i);
    }
    flag = 1;
  }
  if (mini == 10000000)
    cout << -1;
  else
    cout << mini;
}
