#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFS = 1e18;
const int MOD = INF + 7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    a[s] = c;
  }
  for (int i = 0; i < (1000); i++) {
    int cnt = i;
    bool ja = true;
    for (int j = 0; j < (n); j++) {
      if (a[n - j] != cnt % 10) {
        ja = false;
      }
      cnt /= 10;
    }
    if (ja) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
