#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const int INF = 1e9;
const long long LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; i++) {
    string t = to_string(i);
    while ((int)t.size() != 3) {
      t = '0' + t;
    }
    bool b = true;
    for (int j = 0; j < (m); ++j) {
      if ((int)(t[s[j] - 1] - '0') != c[j]) b = false;
    }
    if (b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
