#include <bits/stdc++.h>
using namespace std;
const int N = 25, mod = 998244353;
int n, m, s[N], c[N];
string trans(int u) {
  string ww;
  while (u) {
    ww.push_back(u % 10 + '0');
    u /= 10;
  }
  reverse(ww.begin(), ww.end());
  return ww;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i <= m - 1; i++) cin >> s[i] >> c[i];
  for (int i = 0; i <= 999; i++) {
    bool t = true;
    string k = trans(i);
    if (((int)k.size()) < n || ((int)k.size()) > n) continue;
    for (int j = 0; j <= m - 1; j++)
      if (k[s[j] - 1] != c[j] + '0') t = false;
    if (t) {
      cout << k;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
