#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 10;
int n, m;
int s[M], c[M];
string get(int t) {
  if (!t) return "0";
  string s;
  while (t) {
    s += '0' + t % 10;
    t /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 702; i < N; i++) {
    string t = get(i);
    if (t.size() != n) continue;
    bool flag = true;
    for (int j = 0; j < m; j++)
      if (t[s[j] - 1] != c[j] + '0') flag = false;
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
  return 0;
}
