#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int used[5];
void solve() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    if (s[i] > n) {
      cout << -1;
      return;
    }
    if (s[i] == 1) {
      if (c[i] == 0) {
        cout << -1;
        return;
      } else {
        if (!used[s[i]]) {
          used[s[i]] = c[i];
        } else {
          if (used[s[i]] != c[i]) {
            cout << -1;
            return;
          }
        }
      }
    } else {
      if (!used[s[i]]) {
        used[s[i]] = c[i];
      } else {
        if (used[s[i]] != c[i]) {
          cout << -1;
          return;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) cout << used[i];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
