#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
int main() {
  int n, m;
  cin >> n >> m;
  int s[5], c[5];
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  int num[n];
  for (int i = 0; i < n; ++i) num[i] = -1;
  for (int i = 0; i < m; ++i) {
    if (num[s[i] - 1] != -1 && num[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      num[s[i] - 1] = c[i];
    }
  }
  if (n == 1)
    cout << num[0] << endl;
  else {
    if (num[0] == -1 || num[0] == 0)
      cout << -1 << endl;
    else {
      for (int i = 0; i < n; ++i) {
        if (num[i] == -1)
          cout << 0;
        else
          cout << num[i];
      }
      cout << endl;
    }
  }
  return 0;
}
