#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); i++) cin >> s.at(i) >> c.at(i);
  int ans = -1;
  if (n == 3) {
    for (int i = 100; i <= 999; i++) {
      bool flag = 1;
      string temp = to_string(i);
      for (int j = 0; j < (m); j++) {
        if (temp.at(s.at(j) - 1) != c.at(j)) flag = 0;
      }
      if (flag == 0) continue;
      ans = i;
      break;
    }
  }
  if (n == 2) {
    for (int i = 10; i <= 99; i++) {
      bool flag = 1;
      string temp = to_string(i);
      for (int j = 0; j < (m); j++) {
        if (s.at(j) > temp.size()) {
          flag = 0;
          break;
        }
        if (temp.at(s.at(j) - 1) != c.at(j)) flag = 0;
      }
      if (flag == 0) continue;
      ans = i;
      break;
    }
  }
  if (n == 1) {
    for (int i = 1; i <= 9; i++) {
      bool flag = 1;
      string temp = to_string(i);
      for (int j = 0; j < (m); j++) {
        if (s.at(j) > temp.size()) {
          flag = 0;
          break;
        }
        if (temp.at(s.at(j) - 1) != c.at(j)) flag = 0;
      }
      if (flag == 0) continue;
      ans = i;
      break;
    }
  }
  if (n == 1 && c.at(0) == '0') ans = 0;
  cout << ans << endl;
}
