#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const long long INFLL = (long long)INF * (long long)INF;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  int s, c;
  int flag = 1;
  scanf("%d%d", &n, &m);
  vector<int> number(n, 0);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s, &c);
    if (number[s - 1] == 0 || number[s - 1] == c) {
      number[s - 1] = c;
    } else {
      flag = 0;
      cout << "-1";
      break;
    }
  }
  int flag2 = 0;
  if (flag == 1) {
    for (auto first : number) {
      if (first != 0) {
        flag2 = 1;
      }
    }
    if (flag2 == 0) {
      cout << "-1";
    } else {
      for (auto ans : number) {
        cout << ans;
      }
    }
  }
  return 0;
}
