#include <bits/stdc++.h>
using namespace std;
const int N = 6;
int s[N], c[N];
int main() {
  long long n, m;
  int flag = 0;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v[i].first = a;
    v[i].second = b;
  }
  for (int i = 0; i < 1000; i++) {
    string t = to_string(i);
    if (n == t.size()) {
      int j;
      for (j = 1; j <= m; j++) {
        if (t[v[j].first - 1] - '0' != (v[j].second)) break;
      }
      if (j == m + 1) {
        cout << i << endl;
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0) cout << -1 << endl;
  return 0;
}
