#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
    if (n != 1 && s[i] == 1 && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (i > 0) {
      for (int j = 0; j < (i); ++j) {
        if (s[j] == s[i] && c[j] != c[i]) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < (n); ++i) {
    int keta = i + 1;
    int found = 0;
    for (int j = 0; j < (m); ++j) {
      if (keta == s[j]) {
        cout << c[j];
        found = 1;
        break;
      }
    }
    if (found == 0) {
      if (keta == 1) {
        cout << "1";
      } else {
        cout << "0";
      }
    }
  }
  cout << endl;
}
