#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long k) {
  if (k <= 1) {
    return false;
  }
  if (k == 2) {
    return true;
  }
  if (k % 2 == 0) {
    return false;
  }
  long long i = 3;
  while (i * i <= k) {
    if (k % i == 0) {
      return false;
    }
    i += 2;
  }
  return true;
}
long long binomialCoeff(long long n, long long k) {
  long long C[n + 1][k + 1];
  long long i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i) {
        C[i][j] = 1;
      } else {
        C[i][j] = (C[i - 1][j - 1] % 1000000007 + C[i - 1][j] % 1000000007) %
                  1000000007;
      }
    }
  }
  return C[n][k] % 1000000007;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long srihrg(long long n, long long k, long long m) {
  long long ans;
  ans = 1;
  for (long long i = 0; i < k; i++) {
    ans = (ans * n) % m;
  }
  return ans;
}
long long kk = 1;
void dfsi(vector<bool> &vis, vector<long long> adj1[], long long n,
          long long start, vector<long long> &pre, vector<long long> &pos) {
  vis[start] = true;
  pre[start] = kk;
  kk++;
  for (long long i : adj1[start]) {
    if (!vis[i]) {
      vis[i] = true;
      dfsi(vis, adj1, n, i, pre, pos);
    }
  }
  pos[start] = kk;
  kk++;
}
void bfsi(vector<long long> &dis, vector<long long> adj[], long long s,
          vector<long long> &parent) {
  dis[s] = -1;
  queue<long long> q;
  q.push(s);
  while (!q.empty()) {
    long long z = q.front();
    q.pop();
    for (long long v : adj[z]) {
      if (dis[v] == 0) {
        q.push(v);
        dis[v] = -dis[z];
        parent[v] = z;
      }
    }
  }
}
void make_set(long long v, vector<long long> &parent,
              vector<long long> &krank) {
  parent[v] = v;
  krank[v] = 0;
}
long long find_set(long long v, vector<long long> &parent,
                   vector<long long> &krank) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v], parent, krank);
}
void union_sets(long long a, long long b, vector<long long> &parent,
                vector<long long> &krank) {
  a = find_set(a, parent, krank);
  b = find_set(b, parent, krank);
  if (a != b) {
    if (krank[a] < krank[b]) swap(a, b);
    parent[b] = a;
    if (krank[a] == krank[b]) krank[a]++;
  }
}
void dijkstra(long long s, vector<long long> &dist, vector<long long> &parent,
              long long n, vector<pair<long long, long long>> adj[]) {
  dist[s] = 0;
  vector<bool> u(n, false);
  for (long long i = 0; i < n; i++) {
    long long v = -1;
    for (long long j = 0; j < n; j++) {
      if (!u[j] && (v == -1 || (dist[j] < dist[v]))) v = j;
    }
    if (dist[v] == 1000000007) break;
    u[v] = true;
    for (auto j : adj[v]) {
      long long a, b;
      a = j.first;
      b = j.second;
      if (dist[v] + b < dist[a]) {
        dist[a] = dist[v] + b;
        parent[a] = v;
      }
    }
  }
}
int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[m], b[m];
  for (long long i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  bool t = true;
  for (long long i = 0; i < m; i++) {
    for (long long j = i + 1; j < m; j++) {
      if (a[i] == a[j] && b[i] != b[j]) {
        t = false;
        break;
      }
    }
    if (t == false) {
      break;
    }
  }
  long long ans = 0;
  vector<long long> aa(n, 0);
  if (t == true) {
    bool z = false;
    for (long long i = 0; i < m; i++) {
      if (a[i] == 1 && b[i] == 0) {
        z = true;
      }
      aa[a[i] - 1] = b[i];
    }
    if (aa[0] == 0 && z == false && n != 1) {
      aa[0] = 1;
    }
    if (z == false) {
      for (long long i = 0; i < n; i++) {
        cout << aa[i];
      }
    } else {
      cout << -1;
    }
  } else {
    cout << -1;
  }
  return 0;
}
