#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int x, y;
  if (n == 1) {
    x = 0;
    y = 9;
  } else if (n == 2) {
    x = 10;
    y = 99;
  } else {
    x = 100;
    y = 999;
  }
  for (int i = x; i <= y; i++) {
    int p = i;
    vector<int> v;
    v.clear();
    while (p) {
      v.push_back(p % 10);
      p = p / 10;
    }
    reverse(v.begin(), v.end());
    int f = 0;
    for (int j = 0; j < m; j++) {
      if (s[j] - 1 > v.size()) {
        f = 1;
        break;
      }
      if (v[s[j] - 1] != c[j]) f = 1;
    }
    if (f == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
