#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
using namespace std;
const double EPS = 1e-9;
const long long INF = 1e15;
std::istream &operator>>(std::istream &in, set<int> &o) {
  long long a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
const int mod = 1000000007;
bool check(vector<int> &bingo, int i, int j, int k) {
  return bingo[i] == -1 && bingo[j] == -1 && bingo[k] == -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> number(n, -1);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
      ;
    }
    if (number[s] == -1) {
      number[s] = c;
    } else if (number[s] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
      ;
    }
  }
  if (number[0] == -1) number[0] = 1;
  for (int i = 1; i < n; i++) {
    if (number[i] == -1) number[i] = 0;
  }
  for (int num : number) cout << num;
  cout << endl;
}
