#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const double PI = acos(-1);
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> t(n, -1);
  bool flag = 1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s > m)
      flag = 0;
    else if (t[s - 1] != -1 && c != t[s - 1])
      flag = 0;
    else if (s == 1 && c == 0)
      flag = 0;
    else
      t[s - 1] = c;
  }
  if (flag) {
    if (t[0] == -1) t[0] = 0;
    for (int i = 0; i < n; i++) {
      if (t[i] == -1) t[i] = 0;
      cout << t[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
