#include <bits/stdc++.h>
using namespace std;
vector<int> a[1000];
int b[5];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) a[i].clear();
  int s, c;
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    a[s].push_back(c);
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      if (a[1].size()) {
        for (auto v : a[1])
          if (v != a[1][0]) {
            cout << -1 << endl;
            return 0;
          }
        sort(a[1].begin(), a[1].end());
        b[1] = a[1][0];
      } else {
        if (n == 1)
          b[1] = 0;
        else
          b[1] = 1;
      }
    } else {
      if (a[i].size()) {
        for (auto v : a[i])
          if (v != a[i][0]) {
            cout << -1 << endl;
            return 0;
          }
        sort(a[i].begin(), a[i].end());
        b[i] = a[i][0];
      } else
        b[i] = 0;
    }
  }
  for (int i = 1; i <= n; i++) cout << b[i];
  return 0;
}
