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