#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = long long(1e18) + 1;
const int MAXN = -1;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> a;
  for (int i = 0; i < (n); ++i) {
    a[i] = MAXN;
  }
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s -= 1;
    if (a[s] != MAXN & a[s] != c) {
      cout << "-1";
      return 0;
    } else {
      a[s] = c;
    }
  }
  if (a[n - 1] == MAXN) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < (m); ++i) {
    if (a[i] == MAXN) a[i] = 0;
  }
  string ans = "";
  map<int, int>::iterator it;
  for (it = a.begin(); it != a.end(); it++) {
    ans += to_string(it->second);
  }
  ans = ans.substr(0, ans.size());
  cout << ans;
}
