#include <bits/stdc++.h>
using namespace std;
int mypow(int n, int m) {
  int p = 1;
  for (int i = 0; i < m; i++) {
    p = p * n;
  }
  return p;
}
int main() {
  int n, m;
  cin >> n >> m;
  int max_n = (int)pow(10, n);
  int s[100], c[100];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = 0;
  for (int z = 0; z < n; z++) {
    int start = mypow(10, z);
    int end = mypow(10, z + 1);
    for (int zz = start; zz < end; zz++) {
      int x = 0;
      for (x = 0; x < m; x++) {
        if (n - s[x] > z) break;
        int ten = (mypow(10, (n + 1 - s[x]) - 1));
        int val = zz / ten % 10;
        if (val != c[x]) {
          break;
        }
      }
      if (x == m) {
        cout << zz << endl;
        return 0;
      }
    }
  }
  cout << "-1" << endl;
}
