#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    vector<int> digit(n + 1, 0);
    digit[1] = 1;
    vector<bool> chng(n + 1, 0);
    bool fail = false;
    for (int i = 0; i < m; i++) {
      int c, s;
      cin >> s >> c;
      if (chng[s] && digit[s] != c) {
        fail = true;
      } else {
        chng[s] = true;
        digit[s] = c;
      }
    }
    if (digit[1] == 0) {
      fail = true;
    }
    if (fail) {
      cout << "-1\n";
    } else {
      for (int i = 1; i <= n; i++) {
        cout << digit[i];
      }
      cout << '\n';
    }
  }
}
